Mike Buss Mike Buss - 6 months ago 57
iOS Question

self.navigationController.navigationBar setHidden:NO not working when view controllers are swapped out

I'm experiencing some weird behavior with hiding and showing the UINavigationBar.

In my

viewWillAppear
method I'm calling this:

self.navigationController.navigationBar.hidden = YES;


and when the user presses a button I'm calling this:

self.navigationController.navigationBar.hidden = NO;


and then swapping out the current view controller using the viewControllers property of a custom UINavigationController.

This works fine, but if I try to show the navigationBar using the same line in the
viewWillDisappear
method, it doesn't work. The navigationBar is still hidden.

I'm able to show/hide the status bar in
viewWillDisappear
using the following method:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];


but showing/hiding the UINavigationBar doesn't work!

EDIT: Also,
self.navigationController.isNavigationBarHidden
returns
NO
after I try to show the bar in
viewWillDisappear
but the bar is still hidden.

Any help would be greatly appreciated. Thank you!

Answer

Because you’ve already swapped the current view controller out of the stack, self.navigationController is probably nil when viewWillDisappear is called.

Comments