TabBarController inside NavigationController

蹲街弑〆低调 提交于 2019-12-24 10:43:31

问题


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


回答1:


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 ...

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];

Then, from the tabBarContoller view, based on some action, you can choose to pop it:

[self.navigationController popViewControllerAnimated: NO];



回答2:


You can wire it up in the storyboard editor in the latest version of Xcode.

However, since this is very much non-standard use of the controls, you would need a very good reason as to why you would want a UI like this.

And even then, Apple's review process might turn your app down if the interface is clunky.



来源:https://stackoverflow.com/questions/7825931/tabbarcontroller-inside-navigationcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!