问题
I am currently working on an app which presents a screen modally and another custom progress indicator modally. Is it possible to return to the root View Controller seamlessly?
Home -> screen1-> screen2(Custom progressIndicator)
I want to dismiss the custom progressIndicator (and the screen presented modally) and return to my home (root) View Controller in one go.
self.navigationController?.popToRootViewControllerAnimated(true)
Thank you for the help!
回答1:
You need to dismiss presented model then you can pop all the pushed view controllers. As presented model would not be in the stack of the navigation.
self.dismissViewControllerAnimated(true, completion: {});
Then you can pop to base view controller.
self.navigationController.popViewControllerAnimated(true);
回答2:
If you use presentViewController
, you can use
[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
to go back to root view. It works on IOS9.
回答3:
Swift 4
self.dismiss(animated: true, completion: {});
self.navigationController?.popViewController(animated: true);
回答4:
In Swift 3 this will work:
self.dismiss(animated: true, completion: {});
self.navigationController?.popViewController(animated: true);
来源:https://stackoverflow.com/questions/34326632/how-to-return-to-root-view-controller