Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between UINavigationController and UINavigationItem

I don't understand what is the difference between self.navigationcontroller.navigationitem and self.navigationitem i have navigation based application and in viewDidLoad method in rootViewController of navigationController I set the NavigationItem titleView to custom image by using this code

UIImageView* titleImage=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
self.navigationItem.titleView =titleImage;

by the way if i try to change titleview by this way

UIImageView* titleImage=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
self.navigationcontroller.navigationItem.titleView =titleImage;

nothing was happened. , and when navigationcontroller pushed the another view to the stack the titleview of navigationitem is cleared and reference sets to nil, and also i noticed that the references of self.navigationcontroller.navigationitem and self.navigationitem are not the same.

like image 815
taffarel Avatar asked Apr 26 '12 12:04

taffarel


2 Answers

I believe what you are asking is the following: self.navigationController.navigationItem and self.navigationItem. I am ignoring the rest of the question since it is not really essential to the question.

From what I understand self.navigationController.navigationItem is useless since it is accessing navigation item of the navigation controller (ie your rootViewController).What you really want is self.navigationItem, navigation item of the view controller because that is what essentially going to show up in your view controller.

UINavigationController is a subclass of UIViewController so self.navigationController.navigationItem is just a spillover method from subclassing. It does not do anything positive (at least in my experience).

Edit: Read this for further clarification.

like image 81
Byte Avatar answered Oct 14 '22 13:10

Byte


They are Different. If you dynamically add UINavigationController, then you use self.navigationController.navigationItem.

Please better clarify your question.

like image 41
vishiphone Avatar answered Oct 14 '22 14:10

vishiphone