Quote:
Originally Posted by bhil
Actually, I played with it some more, and it appears you don't have to do any of the IBOutlet stuff, you can just use
Code:
[self navigationController]
to access the navigation controller containing the ViewController you are in.
The more I use it the more I hate using IB with the iPhone SDK. It is completely inconsistent in how things are done, with some requiring outlets and some not.
|
My initial impression is also similar. But after [re]reading the official guides for the nth times, they give more sense every time (the guides are definitely NOT the easiest or best-seller reading materials).
navigationController is a property of UIViewController. The following is quoted from
UIViewController reference (requires Apple ID):
navigationController
A parent or ancestor that is a navigation controller. (read-only)
@property(nonatomic, readonly, retain) UINavigationController *navigationController
Discussion
Only returns a navigation controller if the view controller is in its stack. This property is nil if a navigation controller cannot be found.
So, as long as the view controller is in the navigation controller's stack (being 'pushed' to the stack via pushViewController:animated: ), it will have a reference back to the navigation controller. Similar to this are tabBarController and parentViewController (it can be the controller that presents "self" as modal, or the navigation controller, or the tab bar controller, or nil). For these "parents", we don't need to create IBOutlets to refer to them.
Quote:
Originally Posted by rapidbunny
is this similar to "this" in java? but then "this" in java only applies to the object you are on......what is "self" exactly referring to? the delegate?
|
If you're using it inside the DetailedViewController class, then "self" is referring to its instance/object. DetailedViewController itself is a subclass of UIViewController. So, if it's been pushed to the navigation controller's stack previously, [self navigationController] (or self.navigationController) will refer to its "parent", i.e. the navigation controller.