3

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?

Nico
  • 6,269
  • 9
  • 45
  • 85

1 Answers1

4

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

Edward Jiang
  • 2,403
  • 18
  • 13
  • Yes I just saw that. Best way to call it is by overriding `prepareForSegue` in the parent view controller. Calling it for example in `ViewDidLoad` of the child didn't work. Thanks. – Nico Feb 07 '16 at 07:47
  • 2
    Oh -- if you have the view in Interface Builder, there's actually a checkbox in the attributes inspector. Select the view controller and you can see the checkbox in this screenshot: http://imgur.com/wBHDoca – Edward Jiang Feb 07 '16 at 07:51