简体   繁体   中英

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;

你有没有尝试过:

[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 .

您可以在UINavigationController上调用-popToRootViewControllerAnimated: ...

[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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM