iPhone - viewController calling viewController
I have 3 viewControllers A, B and C.
I am on vcA and I push vcB using
[self.navigationController pushViewController:vcB animated:YES];
While vcB is visible, I push vcC.
Now I am inside vcC and would like to remove (or pop) both vcC and vcB at the same time and go directly to vcA. I don't want to go to vcB. How do I do that?
Is it 开发者_运维百科possible to remove vcB from the stack silently while vcC is being shown?
thanks
I think you can mess with them as an array
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray: navigationController.viewControllers];
[viewControllers removeObjectIdenticalTo: removedViewController];
navigationController.viewControllers = viewControllers;
have you tried:
[self.navigationController popToRootViewControllerAnimated:YES];
If you know that A
is always the first controller that you push, then you should be able to do:
[self.navigationController popToRootViewControllerAnimated:YES]
Or if there may be other controllers on the stack before A
, you can do:
[self.navigationController popToViewController:viewControllerA animated:YES]
References.
You could just call -popToRootViewControllerAnimated:
on your UINavigationController
...
[self.navigationController popToRootViewControllerAnimated:YES];
If A is the root, popToRootViewController.
If not,assuming you are keeping to Apple's restrictions on undocumented API usage, I'd suggest that no, you cannot pop both C ans B from the list from C.
Any direct manipulation of the view stack would be hackish, and lead to lots of potential problem
Your best bet would be to set a global flag from C, pop it, and in B's viewWillAppear (WILL appear, non DID appear), you check for the state of said flag, and if set, immediately pop to A.
View B will not appear, and at worst will cause a small, probably imperceptible lag between C and A.
精彩评论