Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between navigationController.navigationBarHidden and navigationController.navigationBar.hidden?

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.

like image 693
Aleks G Avatar asked Jun 24 '12 11:06

Aleks G


1 Answers

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.

like image 85
Omar Abdelhafith Avatar answered Oct 02 '22 01:10

Omar Abdelhafith