Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 913
Nico Avatar asked Jun 26 '26 22:06

Nico


1 Answers

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

like image 53
Edward Jiang Avatar answered Jun 29 '26 11:06

Edward Jiang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!