Different navigation bar tints inside 1 single navigation controller?
-
29-09-2019 - |
Question
My application has a navigation view controller with 2 views :
- a root view : i'd like the tint color for its navigation bar to be black
- a sub view : i'd like the tint color for its navigation bar to be blue
To achieve this, I set the tint color for the navigation bar in the viewDidLoad method of each view controller :
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
My problem is that during the tests :
- step 1 - i access the root view : the navigation bar is black : OK
- step 2 - i push the subview : the navigation bar is blue : OK
- step 3 - i click on the "back" button of the subview : the navigation remains blue : KO
Is there any add code I should add to obtain the behavior I want ? (i've tried some dirty workarounds like calling drawRect in viewWillAppear but it does not work)
Thanks for your help !
Solution
You should be able to do the self.navigationController.navigationBar.tintColor = [UIColor blackColor];
in viewWillAppear
or viewDidAppear
OTHER TIPS
The reason is that the navigationController is shared. So, when you change its color to Blue, you have to change it back to Black.
The best way is like Elfred said, you should do it in viewWillAppear