1
votes

My apps entire navigational system is built around a navigation controller. All my vc's get pushed in and out of it. I have a menu system 'drawer' that comes out of the left side, which is apart of my custom navigation controller. In the menu I can access multiple areas of the app. Some of those areas result in needing a TabBarController. When I get to that TabBarController it has anywhere from 2-4 tabs and each one is its own VC. There are content on each one of those tabs that can be pressed, which would result in pushing a new page onto the navigation controller.

I know that you are supposed to embed your nav controller inside of the TabBarController, but how can I do that when my whole app is based around a nav controller with certain pages containing TabBarControllers?

I have tried having my app start out as a nav controller, then on the pages where tab bars are I have each tab connect to a new nav controller, then that nav controller goes through the content. Doing it that way adds very unexpected problems in the app along with multiple tab bars.

What is the best way to set up something like this? Keep in mind that I never actually push a tabbarcontroller onto my nav controller in a way that allows you to go 'back'. They are base pages, which allow a user to navigate out from.

1
Can you use the tab view as the root view for the whole app, and then the root view for each tab is a navigation controller?nhgrif
@nhgrif I did look at that method, but ran into some issues. If I embed the entire app into a TabBarController it only starts out by having one tab, which is the initial nav controller. I only have a tab bar on certain pages and those pages have multiple tabs. This means for most of the time I would need my tab bar hidden, but how could I show the tab bar on only certain pages and then have multiple tabs? Like I said my app has a 'drawer' menu system, so while on a tab bar page there is a menu item in the nav bar. That needs to be accessible on all tabs.BlueBear

1 Answers

1
votes

Seems to be you are confusing view controllers with view controller container.

TabBar and Navigation Bar are UIViewController Containers unlike like normal UIviewcontroller they have additional functionality to forward callbacks / delegates to their child view controllers. (like viewDidAppear, shouldAutoRotate etc.. )

What's the difference ? UIViewController handles rotation of embedded views and Container handles rotation of embedded view controllers.

Here is apple's link with addional information

seems to be you are adding rootview's of view controllers on top of each other. Instead use methods

-(void)addViewController:(UIViewController*)vc toViewController:(UIVIewController*)baseVC{
   [vc willMoveToParentViewController:baseVC];
   [baseVC addChildViewController:vc]; 
   [baseVC.view addSubview:vc.view]; 
   [vc didMoveToParentViewController:baseVC];
}

With this you can nest UIViewcontrollers till depth of n. Not only 3 levels (which is your case)

Now in your context :

[self addViewController:tabBarController toViewController:rootNavigationController];
[self addViewController:childnNvigationController toViewController:tabBarController];