hidesBottomBarWhenPushed is not working when tabbarcontroller-viewcontroller's are embedded in navigation controller

3k Views Asked by At

My app ui heirarchy look like as shown. UItabbarcontroller -> navigation-controllers -> view-controllers.

enter image description here

The problem am facing is hidesBottomBarWhenPushed is not working when i try to push a new controller from 1st Vc on button click

if let newVc = UIStoryboard.homeSB.instantiateViewController(withIdentifier: NewViewController.identifier()) as? NewViewController{
    self.navigationController?.hidesBottomBarWhenPushed = true
    self.navigationController?.pushViewController(viewAllVc, animated: true)
}

The Tabbar is still showing in the NewVc

3

There are 3 best solutions below

0
Farrukh Makhmudov On BEST ANSWER

To hide the tab bar in new VC you can call this in viewDidLoad():

self.tabBarController?.tabBar.isHidden = true

Also, you should call method hidesBottomBarWhenPushed from your VC, not from the navigation controller:

if let newVc = UIStoryboard.homeSB.instantiateViewController(withIdentifier: NewViewController.identifier()) as? NewViewController{
newVc.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(viewAllVc, animated: true) 
}

Furthermore, you can make it on your new VC storyboard:

enter image description here

hidesBottomBarWhenPushed in developer.apple.com/documentation

1
faisal khan On

//use this method in the view controller where you want to hide tabBar

override var hidesBottomBarWhenPushed: Bool {
    get {
        return navigationController?.topViewController == self
    }
    set {
        super.hidesBottomBarWhenPushed = newValue
    }
}
0
刘亚伦 On

add these codes in your navigationbar.swift

 override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if children.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }