popToRootViewController 后没有显示 Tabbar [英] Tabbar is not showing up after popToRootViewController
问题描述
在我的应用程序中,我通过设置 UIViewController
的 hidesBottomBarWhenPushed
属性来隐藏标签栏.我不确定这种行为是否被设计,当我调用 popToRootViewController
来弹出所有视图控制器堆栈时,如果我之后推送相同的视图控制器,标签栏没有正确显示.即使我在调用 popToRootViewController
后尝试通过设置 isHidden
属性来显示标签栏,但它也不起作用.奇怪的部分是,在标签栏消失后,我推了同一个视图控制器,当我尝试使用手势弹出(滑动弹出)弹出视图控制器(不是 popToRootViewController)时,我可以看到标签栏.虽然它在转换完成时消失了.
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.
- 在两个选项卡上初始化选项卡栏和导航控制器.
- 在一个标签的导航控制器上推送视图控制器(
hidesBottomBarWhenPushed
为真) - 通过调用
popToRootViewController
从导航控制器弹出所有视图控制器4 通过在 tabbarController 上设置 - 推送同一个视图控制器
selectedIndex
来更改标签索引- 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
hidesBottomBarWhenPushed
属性如何详细显示/隐藏标签栏?
How does hidesBottomBarWhenPushed
property work in detail to show/hide tabbar?
推荐答案
我会在我的应用中讨论这个问题.
I'll talk about the problem in my app.
对于每个页面,我都会编辑self.navigationController?.navigationBar.isHidden
和self.tabBarController?.tabBar.isHidden = false
以保证状态viewWillAppear
中的 tabBar 和 navigationBar.
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
.
// 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
}
navigationBar 和 tabBar 可以在您推送新视图控制器或弹出旧视图控制器时保持其状态与上一个视图控制器相同.所以它会让我们在每个视图控制器中设置来控制和确保它的状态.
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.
这篇关于popToRootViewController 后没有显示 Tabbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!