Reputation: 399
I want to go back to the first view controller. So, I used [self.navigationController popToRootViewControllerAnimated:NO]
from the third view. But, it goes back to just the second view. Do I have to use popToViewController: animated:
instead?
I pushed the third view like this:
[self.view addSubview:secondController.view]; // from the first view
[self.navigationController pushViewController:thirdController animated:YES]; // from the second view
Upvotes: 0
Views: 841
Reputation: 22698
Remove the second view, before using [self.navigationController popToRootViewControllerAnimated:NO]
:
UIView *v = [self.navigationController.viewControllers objectAtIndex:1];
[v removeFromSuperview];
EDIT:
I am doing like this and works ok (I use this on my third view on the stack):
NSMutableArray *allControllers = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
[allControllers removeObjectAtIndex:1];
[self.navigationController setViewControllers:allControllers animated:NO];
[allControllers release];
[self.navigationController popViewControllerAnimated:YES];
Upvotes: 2
Reputation: 1790
It looks like your navigationController was initiated when pushing the thirdController. Your secondController was not 'pushed' by the navigationController, it was added as a subview, which is quite different. So, when you push the thirdController from the secondController, it thinks your rootController is the secondController.
You have two options here:
You may be able to popToViewController
, as you mentioned...I'm not positive if that will work, but it's possible.
Upvotes: 0