0
votes

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 want to get back on Top view controller of tab when tab change?Jaydeep Vora
why, you can hide navigaitonBar from vc2 in viewDidAppear() and unhide in vc1 viewDidAppear() try this and let me know its working or notMidhun K Mohan
In VC1 I set navigationBar.isHidden = false in viewWillAppear it is done.Alper
@Alper when clicking tabbar you want to back onto Top viewcontroller VC1 right?Jaydeep Vora
@Jaydeep yes there is no problem about turnign back to VC1, but when I turn back to VC1 I want to dismiss VC2 or I dont know if it dismisses automaticallyAlper

1 Answers

1
votes

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