Dismiss current navigation controller when clicked tab bar

妖精的绣舞 提交于 2019-12-11 14:18:13

问题


I have got a tab bar controller and in home view controller i have a navigation controller.

-Tab Bar Controller

-- HomeVC

--- VC1 navigation push -> VC2

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
}

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.


回答1:


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)
    }
}


来源:https://stackoverflow.com/questions/45648597/dismiss-current-navigation-controller-when-clicked-tab-bar

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