我正在尝试以编程方式将NavigationController添加到我的TabBarController应用程序中。
我的代码:
UIViewController *viewController1 = [[FirstViewController alloc]
initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc]
initWithNibName:@"SecondViewController" bundle:nil];
UIViewController *viewController3 = [[ThirdViewController alloc]
initWithNibName:@"ThirdViewController" bundle:nil];
UITabBarController *tabController = [[UITabBarController alloc] init];
tabController.viewControllers = @[viewController1, viewController2, viewController3];
return tabController;
我正在尝试将一个tableview / detailview添加到ThirdViewController,并了解我需要使它成为一个导航控制器来做到这一点。
另一个论坛说我可以做类似下面的事情,但是我在改变我的项目时遇到了各种各样的麻烦。有谁知道如何操作代码的顶部并将NavigationController编程到TabBarController中?
其他人的示例代码
UIViewController *viewController1, *viewController2;
viewController1 = [[[UIViewController alloc] initWithNibName:@"FirstViewController_iPhone"
bundle:nil] autorelease];
UINavigationController *navigationcontroller = [[[UINavigationController alloc]
initWithRootViewController:viewController1] autorelease];
viewController2 = [[[UIViewController alloc]
initWithNibName:@"SecondViewController_iPhone" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationcontroller,
viewController2, nil];
我尝试过将它们放在一起,看起来像这样:
UIViewController *viewController1 = [[FirstViewController alloc]
initWithNibName:@"PDCFirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc]
initWithNibName:@"SecondViewController" bundle:nil];
viewController3 = [[UIViewController alloc] initWithNibName:@"ThirdViewController"
bundle:nil];
UINavigationController *navigationcontroller = [[UINavigationController alloc]
initWithRootViewController:viewController3];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray
arrayWithObjects:viewController1,viewController2,navigationcontroller, nil];
return 0;
我没有收到任何错误,应用程序就退出了。任何帮助都会很棒!谢谢大家!