Andrey Chernukha
Andrey Chernukha

Reputation: 21808

TabBarController inside NavigationController

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

Upvotes: 1

Views: 2444

Answers (2)

bryanmac
bryanmac

Reputation: 39296

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

Upvotes: 3

Jason
Jason

Reputation: 11832

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.

Upvotes: 0

Related Questions