UITableView too wide for portrait iPad
This has been driving me mad for a few days...
- Create a new Window-based application for iPad.
- Create a new UITableViewController class,开发者_运维技巧 targeted for iPad, with XIB.
- Add the UITableViewController view as a subview to the AppDelegate window.
- Set the table style to Grouped in the nib.
- Run in iPad simulator and the table cells go off right-hand end of screen
If I allow rotation and reload the tableView then it's subsequently sized correctly. Run on iPhone sim displays fine, just iPad portrait initial view that is mis-sized.
I had a similar problem with a UITableView in a sub-view on my window. I solved it by setting the size of the frame of my UINavigationController in viewDidLoad. For some reason the subview was not constraining itself to the size of the view specified in Interface Builder. Here is what worked for me:
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationController *navigationController = [[UINavigationController alloc] init];
RootViewController *rootController = [[[RootViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];
rootController.managedObjectContext = self.managedObjectContext;
[navigationController.navigationBar setBarStyle:UIBarStyleBlackOpaque];
[navigationController pushViewController:rootController animated:YES];
[navigationController.view setFrame:CGRectMake(0, 0, 500, self.view.frame.size.height)];
[self.leftView addSubview:[navigationController view]];
}
make sure the origin x&y point is 0,0 for UITableViewController, and look into the autosizing property of UITableViewController
精彩评论