How to return to Root View Controller

白昼怎懂夜的黑 提交于 2020-12-01 10:58:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!