2

I have 5 view controllers(say A,B,C,D,E) in my navigation stack. ViewController E is in the top of the stack. On a button click in ViewController E, I want to move to ViewController C. For that I am using the following code.

NSMutableArray *navigationarray = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[navigationarray removeObjectAtIndex:4];
[navigationarray removeObjectAtIndex:3];
self.navigationController.viewControllers = navigationarray;
[navigationarray release];

Is there a better way to do this, where I can check which viewController is being removed from the navigation array

Edit: In this case, could I check whether the viewcontroller being removed isKindOfClass of the class of the particular view controller like

if ([[navigationarray objectAtIndex:4] isKindOfClass:[MyClass class]])
4

1 回答 1

3

Popping view controller from navigation controller is the easy way. This will remove VC E and D.

[self.navigationController popToViewController:viewControllerC animated:YES];
于 2012-05-16T05:21:18.947 回答