Reputation: 60
I used a "push" segue from a ViewController after using the menu in XCode Editor > Embed In > Navigation Controller. I have a button on this presented view that slides in from the side that I would like to dismiss the pushed view. I realize there is a method:
[self.navigationController popViewControllerAnimated:YES];
But I don't have a pointer to the Navigation Controller I added through the XCode menu..
My App Delegate has the window's root view controller as my main ViewController - so I haven't done anything there after adding the Navigation Controller from the XCode menu.
How can I get a pointer to this added Navigation Controller so I can call the pop method programmatically on the pushed view controller? Thanks!
Upvotes: 1
Views: 1282
Reputation: 25740
That is the correct function to use, and will automatically return the navigation controller that you "pushed" into.
From the UIViewController class reference:
navigationController
The nearest ancestor in the view controller hierarchy that is a navigation controller. (read-only)
@property(nonatomic, readonly, retain) UINavigationController
*navigationControllerDiscussion
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.
Upvotes: 1