Reputation: 1925
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
Upvotes: 1
Views: 3056
Reputation: 528
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.
Upvotes: 1