0

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.

Alper
  • 1,415
  • 2
  • 13
  • 20

1 Answers1

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)
    }
}
Jaydeep Vora
  • 6,085
  • 1
  • 22
  • 40
  • Well I have deleted viewWillAppear inside VC1 and wrote your code in tabbar controller, I think it worked :) – Alper Aug 12 '17 at 10:04