刚刚创建了一个新项目,我有4个视图控制器,我添加到UINavigationController
,如下所示:
WatchViewController *first = [[WatchViewController alloc] init];
BetViewController *second = [[BetViewController alloc] init];
Settings *third = [[Settings alloc] init];
Account *forth = [[Account alloc] init];
UINavigationController *navFirst = [[UINavigationController alloc]initWithRootViewController:first];
UINavigationController *navSecond = [[UINavigationController alloc]initWithRootViewController:second];
UINavigationController *navThird = [[UINavigationController alloc]initWithRootViewController:third];
UINavigationController *navForth = [[UINavigationController alloc]initWithRootViewController:forth];
将它们加载到数组中:
NSArray *viewArray = [[NSArray alloc] initWithObjects:navFirst, navSecond, navThird, navForth, nil];
加载标签栏和窗口:
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewArray animated:YES];
[self.window setRootViewController:self.tabController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
所有视图都只是标准视图。当我尝试运行应用程序时,它会响应:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
我无法弄清楚我错过了什么。有什么帮助吗?
答案 0 :(得分:1)
试试这个:
WatchViewController *first = [[WatchViewController alloc] initWithNibName:@"WatchViewController" bundle:Nil];
BetViewController *second = [[BetViewController alloc] initWithNibName:@"BetViewController" bundle:Nil];
Settings *third = [[Settings alloc] initWithNibName:@"Settings" bundle:Nil];
Account *forth = [[Account alloc] initWithNibName:@"Account" bundle:Nil];
/*Your View Navigation Stuff and your viewArray*/
self.tabController.viewControllers = viewArray;
答案 1 :(得分:1)
不要创建4个导航控制器。应通过viewControllers
方法将导航所需的控制器分配到UINavigationController
中的setViewControllers:animated:
属性。
您应该创建1个NavigationController并添加4个UIViewControllers的数组。
这里给出了一个非常好的例子:example并且不要忘记在这里UINavigationClass
答案 2 :(得分:1)
为什么不通过在xib中设置控制器来尝试UINavigationController
内的UITabBarController
。它对我有用。
答案 3 :(得分:0)
抱歉,我烦恼地将UINavigationController子类化为UIViewController。我没有接受它,因为如果我没有使用NavControllers应用程序运行正常,添加导航控制器,它就破了。 :(