问题
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.
- init tabbar and navigation controllers on two tabs.
- push view controller (
hidesBottomBarWhenPushed
is true) on one tab's navigation controller - pop all view controller from the navigation controller by calling
popToRootViewController
4 change tab index by settingselectedIndex
on tabbarController - 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