iPhone : how can i move to front page in navigation Controller?
how can I move to front page in navigation Controller?
i know that if i want to move to rootpage, i can use
[self.navigationController popToRootViewControllerAnimated:YES];开发者_Go百科
but i want to move in front of 2pages. not root page and before page.
how can I do for it?
If you know the viewController on the navigation bar's view controller stack then you can use:
[self.navigationController popToViewController:viewControllerToShow animated:YES];
popToViewController:animated:
Pops view controllers until the specified view controller is at the top of the navigation stack.
Yes you can use
popToViewController:animated:
Pops view controllers until the specified view controller is at the top of the navigation stack.
In addition to the above answers, if you can't have an instance of the view controller you can do so by the index of the view controller in the stack.
NSArray *array = [self.navigationController viewControllers];
[self.navigationController popToViewController:[array objectAtIndex:2] animated:YES];
If you hold a reference to the mentioned ViewController*, you can use;
[self.navigationController popToViewController:(UIViewController *) animated:(BOOL)];
This way it goes back till it reaches the given ViewController.
Other workarounds can be, going to root and then navigating to the main page (if it is level 1, of course) without animation. Or you can pop the ViewControllers one by one, till you are there... It all depends on your structure.
Beware though, if you are holding a reference to the mentioned ViewController, you need to retain/release it properly.
I hope it helps
精彩评论