Search code examples
iosobjective-cuiviewcontrolleruitabbarcontrollershow-hide

iOS - Cannot Push View Controller with TabbarController Showing


My storyboard is as below:

enter image description here

UINavigationController 
    |
 UITabbarController
      |
    HomeVC - Container
                 |
               PageViewController
                    |
                  MainVC | MenVC | WomenVC | ElectronicsVC ...

I try to push a new view controller from MainVC, using tabbarcontroller. I want the bottom tabbar to be visible but I can't. Everytime when new viewcontroller is pushed, it will be in full screen.

In my NavigationHelper.m,

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainV3" bundle:nil];
    MyNewViewController *myNewVC = [storyboard instantiateViewControllerWithIdentifier:@"MyNewViewController"];
    [myTabbarController setHidesBottomBarWhenPushed:NO];
    [myTabbarController.navigationController pushViewController:myNewVC animated:YES];

    // I have checked myTabbarController and myNewVC instances are not nil.

The reason why I use pageviewcontroller in this design because I need few view controllers in first item of tabbarcontroller.

Set tabbarcontroller setHidesBottomBarWhenPushed property to YES before I push new controller is not working too.

I have checked the container inside HomeVC is not covering the tabbar.


Solution

  • This happens because when you invoke push on myTabbarController.navigationController, you actually add one more controller on the same hierarchy level as your UITabBarController controller.

    UINavigationController 
          |
      UITabBarController  –> YourPushedViewController
    

    Which obviously hides entire UITabBarController along with its bar and everything it contains.

    If you want to have navigation inside particular tab — you should place UINavigationController inside this tab, and then do push using it.

    So your new hierarchy should be something like this.

    UITabBarController
        |
       FirstTab — SecondTab — ...
        |
       UINavigationController
        |
       HomeVC - Container
                  |
               PageViewController
                    |
                  MainVC | MenVC | WomenVC | ElectronicsVC ...