1
votes

I want to hide navigation bar in a particular view controller in my TabBarController

Following is code in my first view controller of tabbar

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)
    self.navigationController?.setNavigationBarHidden(true, animated: false)
 }

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(true)
    self.navigationController?.setNavigationBarHidden(false, animated: false)

}

But sometimes when I change tabbar selection viewWillAppear is not called also if I present view from this controller viewWillAppear is not called on dismissal of presented controller.

Due to which facing issues. how to fix this?

Also viewWillDisappear is not called if I push a view controller following is code for it

    let flightVC = AppStrings.appStoryBoard.instantiateViewController(withIdentifier: "flightViewPagerControllerID") as! FlightViewPagerController



    self.navigationController?.pushViewController(flightVC, animated: true)
1

1 Answers

1
votes

For the viewWillAppear not firing when the tab bar selection changes, I think it's better to override optional func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) and hide/unhide based on your viewController.

In case of viewWillAppear not being called on dismissal of presented controller, make sure your modalPresentationStyle is set to .fullScreen

Edit: As per the updated question I think you should either use navigationController(_:didShow:animated:) or navigationController(_:willShow:animated:) for detecting whether a view has been pushed.