如何返回到Root View Controller

Ron*_*oh1 5 navigation ios swift

我目前正在开发一个应用程序,它以模态方式显示屏幕和另一个自定义进度指示器.是否可以无缝地返回根视图控制器?

首页 - > screen1-> screen2(自定义progressIndicator)

我想解雇自定义progressIndicator(以及模态显示的屏幕)并一次性返回我的家(根)View Controller.

 self.navigationController?.popToRootViewControllerAnimated(true)
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助!

小智 9

您需要关闭显示的模型,然后您可以弹出所有推送的视图控制器.如所呈现的模型不会在导航的堆栈中.

self.dismissViewControllerAnimated(true, completion: {});
Run Code Online (Sandbox Code Playgroud)

然后你可以弹出到基本视图控制器.

self.navigationController.popViewControllerAnimated(true);
Run Code Online (Sandbox Code Playgroud)


Yuc*_*hou 8

如果使用presentViewController,可以使用

[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

回到root视图.它适用于IOS9.