1
votes

I have a class X which extends UIViewController. To my surprise this class can have the following code:

[self.navigationController popViewControllerAnimated:YES];

navigationController as far as I see, is a property added by a category in UINavigationController.h:

@interface UIViewController (UINavigationControllerItem)
@property(nonatomic,readonly,retain) UINavigationController *navigationController;  
@end

My class extends UIViewController, not UINavigationController, and I see no way of this category being referred. I thought I had to import the category to access the members declared by it. So how UIViewController has access to a property declared in another, unrelated header file?

Thanks, Janos

1
It already imported for you by adding "<UIKit/UIKit.h>", think about UINavigationController then have you imported "UINavigationController.h" to use UINavigationController? How about UIButton? UILabel?.. Same thing..andykkt
Yes, thanks a lot! I'll be able to sleep now ;)Janos

1 Answers

1
votes

According to Apple documentation UIViewController has navigationController property:

The nearest ancestor in the view controller hierarchy that is a navigation controller. (read-only). If the receiver or one of its ancestors is a child of a navigation controller, this property contains the owning navigation controller. This property is nil if the view controller is not embedded inside a navigation controller.

See UIViewController documentation.