So my app has a UITabBarController. Within that, one of the tabs is a UIViewController containing a UINavigationController. Within that is a UITableViewController.
The problem is that for some reason the size of the TableView is off, and part of the bottom entry of the table is obscured by the TabBar. I've tried everything I can think of to resize the tableview but to no avail. Here are the relevant parts of the code:
AppDelegate
tabBarController = [[UITabBarController alloc] init];
LogbookViewController *firstVC = [[LogbookViewController alloc] init];
PaceCalcViewController *secondVC = [[PaceCalcViewController alloc] init];
SettingsTableViewController *thirdVC = [[SettingsTableViewController alloc] init];
...
// Add them as children of the tab bar controller
tabBarController.viewControllers = [NSArray arrayWithObjects: firstVC, secondVC, thirdVC, nil];
LogbookViewController (subclass of UIViewController)
- (void)viewDidLoad {
[super viewDidLoad];
navigationController = [[UINavigationController alloc] init];
[self.view addSubview:navigationController.view];
WorkoutListTableViewController *listController = [[WorkoutListTableViewController alloc] init];
listController.managedObjectContext = self.managedObjectContext;
[navigationController pushViewController:listController animated:NO];
[listController release];
}
The WorkoutListTableViewController (subclass of UITableViewcontroller) currently doesn't have anything in particular in it that I would think would affect it, but here's the ViewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Workouts";
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"List" style:UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
NSString *paths = [[NSBundle mainBundle] resourcePath];
NSString *fileName = @"short_bg.png";
NSString *filePath = [paths stringByAppendingPathComponent:fileName];
UIImage *paper = [[UIImage alloc] initWithContentsOfFile:filePath];
UIImageView *paper_bg = [[UIImageView alloc] initWithImage:paper];
self.tableView.backgroundView = paper_bg;
[fileName release];
[paper release];
//self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
self.navigationItem.rightBarButtonItem = addButtonItem;
[addButtonItem release];
/*UIBarButtonItem *importButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Import" style:UIBarButtonItemStylePlain target:self action:@selector(importDialogAction:)];
self.navigationItem.leftBarButtonItem = importButtonItem;
[importButtonItem release];*/
}
}
I've tried things like listController.view.frame = CGRectMake(whatever) in the LogbookViewcontroller, or self.tableView.frame - CGRectMake(whatever) in the WorkoutListTableViewController, but nothing has w开发者_C百科orked. Any ideas? I can post more of the code if that helps.
You should be added the Navigation Controller directly to the UITabBarController, then it should size appropriately:
tabBarController = [[UITabBarController alloc] init];
WorkoutListTableViewController *listController = [[WorkoutListTableViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:listController];
PaceCalcViewController *secondVC = [[PaceCalcViewController alloc] init];
SettingsTableViewController *thirdVC = [[SettingsTableViewController alloc] init];
...
// Add them as children of the tab bar controller
tabBarController.viewControllers = [NSArray arrayWithObjects: navController, secondVC, thirdVC, nil];
You don't need the View Controller in the 1st tab to add a UINavigationController to the view, just go ahead and add the TableViewController as the root of the nav controller and add the nav controller into the 1st tab.
精彩评论