Alex Rivera | Logout

Is it possible to pop the UINavigationController twice?

Asked 2012-05-30T19:20:57.023
12

Is it possible to pop the navigation controller twice? I have this navigation structure:

View One ----> View Two -----> View Three

What I'd like to accomplish is that by the tap of a row on View Three, go back directly to View One. I've done it from Three to Two via protocol-delegate, but setting the delegate in view One doesn't work and setting two consecutive delegate-protocol both poping the navigation controller, gives me error: nested navigation controller activity (or something similar).

Any help would be appreciated. Thanks in advance!

Edit
Report

2 Answers

17

Use the following code. You can use any number instead of -3 to pop to a different level.

Obj-C:

ViewController *View = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-3];
    [self.navigationController popToViewController:View animated:YES];

Swift 3.0*:

let controller = self.navigationController?.viewControllers[(self.navigationController?.viewControllers.count)! - 3]        
self.navigationController?.popToViewController(controller!, animated: true)
answered 2013-06-11T11:08:35.063
3

'self' seems to be released after first pop

UINavigationController *navigationController = self.navigationController;
[navigationController popViewControllerAnimated:NO];
[navigationController popViewControllerAnimated:YES];
answered 2012-11-24T09:26:54.817

Your Answer