0

The view controller setup looks like this:

UITabBarController
  - Tab 1
    - UINavigationController
      - UITableViewController
        - select row pushes UIViewController (self.navigationController pushViewController)
          - select button pushes another UIViewController
  - Tab 2
    - UIViewcontroller

My AppDelegate should reflect the setup above and looks like this:

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
  UITabBarController*     tabBarController           = [[UITabBarController     alloc] init];
  UITableViewController*  myListController           = [[MyListController       alloc] init];
  myListController.hidesBottomBarWhenPushed          = YES;
  UINavigationController* navigationControllerMyList = [[UINavigationController alloc] initWithRootViewController:myListController];
  navigationControllerMyList.tabBarItem              = [[UITabBarItem           alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];

  UIViewController* simpleViewController             = [[SimpleViewController   alloc] init];
  simpleViewController.tabBarItem                    = [[UITabBarItem           alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:0];
  tabBarController.viewControllers                   = @[ navigationControllerMyList , simpleViewController ];

  self.window                    = [[UIWindow alloc] init];
  self.window.rootViewController = tabBarController;
  [self.window makeKeyAndVisible];

  return YES;
}

The problem I face is that once I select a row in the table view controller the tab bar hides as expected by setting myListController.hidesBottomBarWhenPushed = YES;

On UINavigationController navigate back the tabbar doesn't show up again but I would expect to show it again. But only if I'm at the root of the navigation controller.

I tried to set tabBar.hidden to NO in the UITableViewController but once I navigated back and for the tabBar is always visible.

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
  self.tabBarController.tabBar.hidden = NO;
}

I saw also this answer which basically says I've to manage the tabbar in every view controller myself. I try to avoid this.

What do I miss to correctly hide and show the tabbar only at the navigation controller root?

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
  • It seems I found a reasonable way to handle this in this answer: https://stackoverflow.com/a/23269013 I'm checking it now – Bruno Bieri May 16 '19 at 15:22
  • Anyone with enough permission feel free to vote as duplicate of: https://stackoverflow.com/q/5641465 I will use the approach https://stackoverflow.com/a/23269013 – Bruno Bieri May 17 '19 at 06:00

1 Answers1

0

Before pushing any VC inside you navigation controller just add a line navigationController?.hideBottomBarWhenPushed = true

Don’t copy paste there might be syntax error, try to type xcode will give suggestion.

Atul Gupta
  • 51
  • 4
  • Thanks for your feedback. I see you posted a line of code I've already tried to use. As I wrot it doesn't give me the desired behavior. I used now the approach I've added as a comment. – Bruno Bieri May 17 '19 at 05:57