我不能为我的生活在我的每个标签栏项目视图中获得导航控制器(和栏)。这是我的appdelegate,我错过了什么? FrontPage
和Opinion
也是tableviewcontrollers,只是忘了他们名字中的表格。
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
FrontPageViewController *frontPageVC = [[FrontPageViewController alloc] initWithNibName:nil bundle:nil];
frontPageVC.title = @"Front Page";
frontPageVC.tabBarItem.image = [UIImage imageNamed:@"second"];
UINavigationController *frontPageNavController = [[UINavigationController alloc] initWithRootViewController:frontPageVC];
CampusTableViewController *campusVC = [[CampusTableViewController alloc] initWithNibName:nil bundle:nil];
campusVC.title = @"Campus";
campusVC.tabBarItem.image = [UIImage imageNamed:@"second"];
UINavigationController *campusNavController = [[UINavigationController alloc] initWithRootViewController:campusVC];
OpinionViewController *opinionVC = [[OpinionViewController alloc] initWithNibName:nil bundle:nil];
opinionVC.title = @"Opinion";
opinionVC.tabBarItem.image = [UIImage imageNamed:@"second"];
UINavigationController *opinionNavController = [[UINavigationController alloc] initWithRootViewController:opinionVC];
SportsTableViewController *sportsVC = [[SportsTableViewController alloc] initWithNibName:nil bundle:nil];
sportsVC.title = @"Sports";
sportsVC.tabBarItem.image = [UIImage imageNamed:@"second"];
UINavigationController *sportsNavController = [[UINavigationController alloc] initWithRootViewController:sportsVC];
PDFViewController *pdfVC = [[PDFViewController alloc] initWithNibName:nil bundle:nil];
NSArray *controllers = [NSArray arrayWithObjects:frontPageVC, campusVC, opinionVC, sportsVC, pdfVC, nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = controllers;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
[[self.tabBarController.viewControllers objectAtIndex:0] setRootViewController:frontPageNavController];
}
谢谢你!
编辑:显然我需要输入更多内容来解释我的问题,因为如果没有一定数量的话,SO会不会让我发帖?
答案 0 :(得分:2)
更改此行
NSArray *controllers = [NSArray arrayWithObjects:frontPageVC, campusVC, opinionVC, sportsVC, pdfVC, nil];
到那个
UINavigationController *pdfNavController = [[UINavigationController alloc] initWithRootViewController:pdfVC];
NSArray *controllers = [NSArray arrayWithObjects:frontPageNavController, campusNavController, opinionNavController, sportsNavController, pdfNavController, nil];
答案 1 :(得分:0)
您的controllers
应包含导航控制器,而不是单个控制器。
NSArray *controllers = [NSArray arrayWithObjects:frontPageNavController, campusNavController, opinionNavController, sportsNavController, pdfNavController, nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = controllers;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
// you can remove the last line: [[self.tabBarController.viewControllers objectAtIndex:0] setRootViewController:frontPageNavController];
Apple在文档中说(不记得是否在人机界面指南中,在视图控制器编程,标签栏控制器编程或导航控制器编程中),如果你想拥有导航控制器和标签栏控制器,你必须将导航控制器放在标签栏控制器内。
答案 2 :(得分:0)
为什么在return语句之后给出这个方法?
[[self.tabBarController.viewControllers objectAtIndex:0] setRootViewController:frontPageNavController];
尝试在return语句之前给出这个或删除此语句。因为你返回下一行不会执行。还要清楚地告诉我们您的问题。你想做什么。