NavigationController 中的 TabBarController [英] TabBarController inside NavigationController
问题描述
想象一下,我们有一个由导航控制器控制的多视图应用程序.我们使用 pushViewController 方法从第一个视图转到第二个视图,这不是问题,但是我们需要移动到第三个视图.第三个是一个看起来像 TabBar 的视图.我们怎么做?第三个视图应该是由 TabBarController 控制的,不是吗?那么如何传递控制呢?我声明了一个插座 UITabBarController * tbc 并将其连接到 xib 文件中的 TabBarController 然后我在 viewDidLoad 中尝试了这个:tbc = [[UITabBarController alloc]init];
Imagine that we have multiview apllication which is controlled by Navigation Controller. We go from the first view to second by using pushViewController method and that's not a problem but then we need to move to the third view. And the third one is a view which looks like a TabBar. How do we do that? The third view is supposed to be controlled by TabBarController, isn't it? So how to pass the control? I declared an outlet UITabBarController * tbc and connected it to TabBarController in xib file and then i tried this in viewDidLoad: tbc = [[UITabBarController alloc]init];
它什么也没显示.非常感谢您的帮助
and it shows nothing. Your help is highly appreciated
推荐答案
有点奇怪.使用 tabBarController 切换视图更标准,其中一些视图可能是导航控制器.但是……
It's a bit wierd. Its more standard to have a tabBarController that switches views and some of those views may be navigation controllers. But ...
创建 UITabBarController 并推送它.
Create the UITabBarController and push it.
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
// create someView
[viewControllers addObject:someView];
// create someView2
[viewControllers addObject:someView2];
UITabBarController *tabController = [[UITabBarController alloc] init];
[tabController setViewControllers:viewControllers];
[[self navigationController] pushViewController:tabController animated:YES];
然后,从tabBarContoller视图,根据一些动作,你可以选择弹出它:
Then, from the tabBarContoller view, based on some action, you can choose to pop it:
[self.navigationController popViewControllerAnimated: NO];
这篇关于NavigationController 中的 TabBarController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!