I found the hard way that
navigationController.navigationBarHidden = NO;
and
navigationController.navigationBar.hidden = NO;
are not the same thing. In fact, if I use the first syntax to hide the nav bar, then I cannot use the second syntax to show it: it simply won't do anything. Moreover, the first syntax to show/hide the nav bar always works for me, while the second syntax works some times, but not always. I haven't been able to determine exactly when it would work and when not.
As I was stuck with fixing somebody else's code (a reasonably large app: over 20 UIViewControllers), I had to do a global search for navigationBar.hidden
and replace it with navigationBarHidden
. After that, I had to do a global search for navigationBar setHidden:
and replace with navigationBarHidden
syntax. This eventually fixed the issue.
Yet, I want to understand why the two different options are provided and what the real difference between them is.
navigationBarHidden applies an animation when hiding or showing the navBar duration of this navigation could be set by using UINavigationControllerHideShowBarDuration
Where navigationBar.hidden will directly change the visiblity status of the UINavigationBar
(which is a subclass of UIView
)
Since UINavigationBar
is a subclass of UIView
it inherited the hidden bool property, no way of changing it to protected or private
From apple docs
The navigation controller is responsible for managing the configuration and display of the navigation bar and navigation toolbar. You must never modify these views directly. Instead, you should manipulate them through the methods and properties of the UINavigationController class. You can hide and show the navigation bar using the navigationBarHidden property or setNavigationBarHidden:animated: method.
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