how to pop a controller off the navigation stack without using the navigation bar
I'm trying to implement a navigation controller with some hierarchical views. I want to use a regular UIViewController to present choices for drilling down, I don't want to use the navigation bar - I want to have my own, custom buttons for returning back up a level.
I see examples like:
[[self navigationController] pushViewController:nextViewController animated:YES];
and my questions are these: Is navigationController
a property of all UIViewControllers? Can I refer to self.navigationController
regardless of the view that's on the stack? If I'm at an arbitrary view, can I have a button action that contains something like [self.navigationController popToRootViewController animated:YES];
Each view I present will need a button to return to the previous view, or to th开发者_运维技巧e root view, depending on the situation. I want to create that button in each view controller and control which view in the stack it returns to. Am I on the right track?
Is navigationController a property of all UIViewControllers?
Yes.
Can I refer to self.navigationController regardless of the view that's on the stack?
Every UIViewController
on the UINavigationController
's stack will return the UINavigationController
object when calling navigationController
on it.
If I'm at an arbitrary view, can I have a button action that contains something like
[self.navigationController popToRootViewControllerAnimated:YES];
Yes. popToRootViewControllerAnimated:
will take the user to the root UIViewController
for the UINavigationController
, and you can use [self.navigationController popViewControllerAnimated:YES];
to just pop off the top UIViewController
. This last one does the same as tapping the Back
UIBarButtonItem
.
Am I on the right track?
Yes :)
精彩评论