问题描述
我有一个标签栏控制器,在主视图控制器中我有一个导航控制器.
I have got a tab bar controller and in home view controller i have a navigation controller.
-标签栏控制器
-- HomeVC
--- VC1 导航推送 -> VC2
--- VC1 navigation push -> VC2
在 VC1 中导航栏没有隐藏,但在 VC2 中是隐藏的.我用 viewwillappear 和 viewwilldisappear 控制它.
In VC1 navigation bar is not hidden but inside VC2 is hidden. And im controlling it with viewwillappear and viewwilldisappear.
override func viewWillAppear(_ animated: Bool) {
navigationController?.navigationBar.barStyle = .blackTranslucent
}
override func viewWillDisappear(_ animated: Bool) {
navigationController?.navigationBar.isHidden = false
}
但是没有滑动就回到VC1,我的意思是点击标签栏homeVC图标隐藏导航栏.我想关闭或弹出当前视图控制器并返回到 VC1.
But turning back to the VC1 without swipe, I mean clicking tab bar homeVC icon hides navigation bar. I want to dismiss or pop current viewcontroller and turn back to VC1.
推荐答案
所以你可以通过 UINavigationController
的 popToRootViewController
来做到这一点.您必须在 UITabBarDelegate
的 tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem)
方法中处理此问题.
So you can do this by popToRootViewController
of UINavigationController
. you have to handle this in tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem)
method of UITabBarDelegate
.
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
if let rootView = self.viewControllers!["Index of VC1 Controller"] as? UINavigationController {
rootView.popToRootViewController(animated: false)
}
}
这篇关于单击选项卡栏时关闭当前导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!