2
votes

In my application, I hide tabbar by setting hidesBottomBarWhenPushed property of UIViewController. I'm not sure this behavior is designed or not, when I called popToRootViewController to pop all view controller stack, tabbar did not show properly if I pushed same view controller after. Even I tried to show tabbar by setting isHidden property after I called popToRootViewController but it didn't work neither. Weird part is, after tabbar disappeared, I pushed same view controller and I could see the tabbar when I tried to pop the view controller (not popToRootViewController) by using gesture to pop (swipe to pop). Though it disappeared when transition was completed.

FYI, this is step by step to produce this behavior.

  1. init tabbar and navigation controllers on two tabs.
  2. push view controller (hidesBottomBarWhenPushed is true) on one tab's navigation controller
  3. pop all view controller from the navigation controller by calling popToRootViewController 4 change tab index by setting selectedIndex on tabbarController
  4. push the same view controller

How does hidesBottomBarWhenPushed property work in detail to show/hide tabbar?

1
Can you edit post with your code at step 2 ?Luan Tran

1 Answers

2
votes

I'll talk about the problem in my app.

For every pages, I'll edit the self.navigationController?.navigationBar.isHidden and self.tabBarController?.tabBar.isHidden = false to guarantee the state of tabBar and navigationBar in the viewWillAppear.

Sample

// In this viewController, I'll show the navigation bar and hide tab bar
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.isHidden = false
    self.tabBarController?.tabBar.isHidden = true
}

The navigationBar and tabBar can keep their state from last view controller when you push a new one or pop a old one. So it will let we set in every view controller to control and ensure its state as I wish.