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]])

1 Answer 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];
Sign up to request clarification or add additional context in comments.

1 Comment

Found this one helpful too.. [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:4] animated:YES];

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.