【发布时间】:2012-08-30 02:23:58
【问题描述】:
根据Apple,我可以使用代码组合UINavigationController和UITabBarController,例如
MyViewController1* vc1 = [[MyViewController1 alloc] init];
MyViewController2* vc2 = [[MyViewController2 alloc] init];
MyViewController3* vc3 = [[MyViewController3 alloc] init];
MyNavRootViewController* vc4 = [[MyNavRootViewController alloc] init];
UINavigationController* navController = [[UINavigationController alloc]
initWithRootViewController:vc4];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, vc3, navController, nil];
tabBarController.viewControllers = controllers;
在这个设置中,只有 vc4 有 UINavigationController,但是如果我想要 vc1-vc3 也有 UINavigationController 怎么办?,我应该喜欢。 .
MyViewController1* vc1 = [[MyViewController1 alloc] init];
UINavigationController* nv1 = [[UINavigationController alloc]
initWithRootViewController:vc1];
MyViewController1* vc2 = [[MyViewController2 alloc] init];
UINavigationController* nv2= [[UINavigationController alloc]
initWithRootViewController:vc2];
MyViewController1* vc3 = [[MyViewController3 alloc] init];
UINavigationController* nv3 = [[UINavigationController alloc]
initWithRootViewController:vc3];
NSArray* controllers = [NSArray arrayWithObjects:nv1, nv2, nv3, nil];
tabBarController.viewControllers = controllers;
这是正确的方法吗?
【问题讨论】:
-
嗯,这取决于您是否想要...你的目标是什么?
-
如果您必须在单个选项卡中浏览多个视图,那么您将需要使用 navigationController。如果每个选项卡要显示单个 ViewController,则不要使用 navigationController。这完全取决于您的要求。
标签: iphone objective-c ios xcode cocoa