marciokoko
marciokoko

Reputation: 4986

UINavigationController pushing UITabBarController only displays one tab

I have an application that has a UITabBarController created in IB. That tbc loads 3 views which work fine up to now.

I decided to INSERT a UINavController as the starting VC and have a UITableViewController display 4 menu items in cells. Each of the 4 items will in essence load the UITabBarController put pass in a different xml file to process in order to display data in those 3 tabs.

I essentially did this at the end of the applicationDidFinishLoading:

MainMenu *rootViewController = [[MainMenu alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.rootViewController = navController;
[window makeKeyAndVisible];
return YES;

I then created the MainMenu as the rootViewController subclassing UITableViewController and added a hardcoded array for now which displays the 4 items I want. I had the didSelectRowAtIndexPath run this code:

tabBarController = [[UITabBarController alloc] init];
[self.navigationController pushViewController:tabBarController animated:YES];
[tabBarController release];

It turns out that when I run it, the navcontroller pushes the tab controller but only the first tab shows up. Here is a pic.

enter image description here

Upvotes: 2

Views: 3632

Answers (1)

Ravi
Ravi

Reputation: 8309

You should never push a UITabBarController from a UINavigationController. Apple clearly says this:

An app that uses a tab bar controller can also use navigation controllers in one or more tabs. When combining these two types of view controller in the same user interface, the tab bar controller always acts as the wrapper for the navigation controllers.`

That essentially means tab bar should be the parent of all other view controllers that get called. Not the other way round. You should probably change the way you present your app.

More information here.

Upvotes: 11

Related Questions