views:

85

answers:

2

I would like to be able to pop multiple views from a UITableViewController stack. For example in the Apple DrillDownSave example, when viewing Level 3 to go back to Level 1 or when viewing an Item to go back to Level 2 when a button is pushed.

I tried:

[self.navigationController.parentViewController.navigationController popViewControllerAnimated: NO];
[self.navigationController popViewControllerAnimated: NO];  

and

[self.navigationController popViewControllerAnimated: NO];  
[self.navigationController.parentViewController.navigationController popViewControllerAnimated: NO];

but these leave me the same place as just a single popViewControllerAnimated:. Is there an easy way to do this?

+1  A: 

What you want is to send popToViewController: animated: to the navigation controller. You can use the navigation controller's viewControllers property to figure out which view controller it is that you want to pop to.

Giao
A: 

Thank you Giao that did it. I changed my code to:

NSArray *allViewControllers = self.navigationController.viewControllers;
NSInteger n = [allViewControllers count];
[self.navigationController popToViewController: [allViewControllers objectAtIndex: (n-3)] animated: YES];

and it works perfectly.

LavaSlider