Nico
Nico

Reputation: 6359

Keep the UINavigationController while moving to next UIViewController but hide UITabBarController

I have a UITableViewController that is embedded in a UINavigationController and in a UITabBarController.

When I select a row, I want to open my UIViewController in the UINavigationController but not in the UITabBarController.

When I create the segue from the cell to my UIViewController in the Interface Builder, I select Show (eg. Push).

The problem is that it keeps the UITabBarController as well.

Then I tried the other kinds of segue but none of them display the UINavigationController.

I thought about adding self.tabBarController?.tabBar.hidden = true in viewDidLoad() and override willMoveToParentViewController:

override func willMoveToParentViewController(parent: UIViewController?) {
    super.willMoveToParentViewController(parent)

    if parent == nil {
        self.tabBarController?.tabBar.hidden = false
    }
}

It works fine except when I make a driven transition (paning from the edge to go back to the parent view controller).

How to do it the proper way?

Upvotes: 3

Views: 157

Answers (1)

Edward Jiang
Edward Jiang

Reputation: 2433

UIViewController has a property named hidesBottomBarWhenPushed which will do exactly what you want.

Just set tableViewController.hidesBottomBarWhenPushed = true and you should be good to go!

See Apple's documentation

Edit: if you're using Interface Builder to construct your views, there's actually a checkbox you can click, so you don't have to set it programmatically.

screenshot of checkbox in interface builder

Upvotes: 4

Related Questions