Tabbar is not showing up after popToRootViewController

强颜欢笑 提交于 2019-12-25 07:57:48

问题


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:


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.



来源:https://stackoverflow.com/questions/43672518/tabbar-is-not-showing-up-after-poptorootviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!