Almazini Almazini - 2 months ago 5x
Swift Question

Navigation bar behaviour in swift

I have three view controllers and they are embedded in navigation controller.

The architecture is the following:
enter image description here

I want to hide navigation bar from first view controller.

For this purpose I use

navigationController?.setNavigationBarHidden(true, animated: true)

in viewdidload method(for first controller).
The same is used in two other controllers but with false parameter to enable navigation bar.

When I load application - all is good, NB is disabled, when I go to second controller also all is fine - it is enabled. BUT! When I press back button on navigation bar of second controller and it sends user to first controller - navigation bar is enabled there.

Is there a special method which should be used when we return back to controller? Can anybody explain this to me? Really appreciate your help.


When you press back button, your view controller viewDidLoad method is not called again (because controller is not recreated) and navigation bar will have the same state as it had before you went back.

In order to update navigation bar for each view controller as it is shown, you have to update it in viewWillAppear method instead of viewDidLoad.