2

I have a tab bar controller with 4 child view controller. Every time the user switches tab bar the navigation items at the top right are supposed to change. They do change, except for one scenario (user going from the third tab).

enter image description here

I must admit that I am changing the navigation items of the navigation bar of the tab bar controller. I am not using four different navigation controllers + view controllers.

// called in viewWillAppear
internal func setupNavigationBar() {
    title = "Meeting"

    if let tabBarVC = parent as? ProjectTabBarController {
        tabBarVC.navigationItem.leftBarButtonItems = nil
        tabBarVC.navigationItem.rightBarButtonItems = nil

        tabBarVC.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(didTapCreateMeeting))
    }
}
Rashwan L
  • 38,237
  • 7
  • 103
  • 107
Cesare
  • 9,139
  • 16
  • 78
  • 130

1 Answers1

2

Use this code to hide the barButtonItems instead:

self.navigationItem.setLeftBarButton(nil, animated: true)
self.navigationItem.setRightBarButton(nil, animated: true)

Then re-set and do whatever you´d like to do and make sure to set these in your viewDidAppear to make sure that your view is updated

Rashwan L
  • 38,237
  • 7
  • 103
  • 107
  • Doesn't seem to be making any changes. I put this code in my view controller super class (viewWillAppear method). I have also tried with `self.tabBarController.navigationItem` – Cesare Oct 18 '17 at 09:33
  • Use your `viewDidAppear` instead to make sure that your view is updated @Cesare – Rashwan L Oct 18 '17 at 09:39
  • If you can update your answer with your last comment I can accept it @Rashwan – Cesare Oct 18 '17 at 09:46
  • @Cesare, sure I have updated the answer. Good luck with your project! – Rashwan L Oct 18 '17 at 09:57