所以我的应用程序有一个UITabBarController。在其中,其中一个选项卡是包含UINavigationController的UIViewController。其中有一个UITableViewController。
问题在于,由于某种原因,TableView的大小已关闭,并且TabBar会使表的底部条目的一部分变得模糊。我已经尝试了所有我能想到的重新调整tableview但无济于事的东西。以下是代码的相关部分:
的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(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];
}
WorkoutListTableViewController(UITableViewcontroller的子类)目前没有任何特别的东西,我认为会影响它,但这里是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];*/
}
}
我在LogbookViewcontroller中尝试了listController.view.frame = CGRectMake(无论如何),或者在WorkoutListTableViewController中尝试了self.tableView.frame - CGRectMake(无论如何),但没有任何效果。有任何想法吗?如果有帮助,我可以发布更多代码。
答案 0 :(得分:0)
您应该将导航控制器直接添加到UITabBarController,然后它应该适当地调整大小:
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];
您不需要在第一个选项卡中使用View Controller将UINavigationController添加到视图中,只需继续添加TableViewController作为导航控制器的根目录,并将导航控制器添加到第一个选项卡中。