dannail
dannail

Reputation: 455

about navigation controller in view controller

In the appdelagate, we have a UINavigationController and the view controllers as well. then in it we can initialize the navigation controller with the root view controller. And I understand why need them too.

However, in the sample code of my reference book(iPhone SDK Application Development, author: Jonathan Zdziarski), all view controller classes were added with a navigation controller as property, while they seem to be never used. So what is the meaning of having them as property in view controller classes?

e.g

@interface XYZViewController: UIViewController
{
  UITextView *textView;
  UIButton *button;
  .....
  .....
  UINavigationController *navigationController;
}

-(void)...

.....
...
@end

One more question:

All UIViewController instances can have the property "navigationItem" once they are navigated. so what do this navigationItem refer to? does it refer to the navigation controller that is navigating the view controller?

Upvotes: 0

Views: 334

Answers (1)

ayoy
ayoy

Reputation: 3835

UIViewController has navigationController property that is handled by the framework and it points to the parent UINavigationController if the view controller in question has one.

Check the documentation for more info:

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html

The same documentation will tell you that navigationItem is a UINavigationItem object that represents a view controller in the navigation bar. You can customise its appearance, like title, prompt, back button behaviour, etc.

That said, I have no idea why your book adds a navigationController property to UIViewController subclasses. It was added in iOS 2.0, a long time ago already... Anyway, you shouldn't need to add it, as it's provided in UIViewController class.

Upvotes: 1

Related Questions