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!
Because you’ve already swapped the current view controller out of the stack, self.navigationController
is probably nil
when viewWillDisappear
is called.
You're better off not messaging self.navigationController
from viewWillDisappear
as eager pointed out since it may be nil
. Rather than holding on to a reference, I recommend editing the navigationBarHidden
property always from within viewWillAppear
as in this answer https://stackoverflow.com/a/27748007/2248638 . I have a BOOL navigationBarHidden
property on my UIViewController
base class so that I only need to set the property once for those view controllers which are hidden.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:self.navigationBarHidden animated:animated];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With