如何 return 到根视图控制器

How to return to Root View Controller

我目前正在开发一个以模态方式显示屏幕和另一个自定义进度指示器的应用程序。是否可以 return 无缝连接到根视图控制器?

主页 -> 屏幕 1-> 屏幕 2(自定义进度指示器)

我想一次性关闭自定义 progressIndicator(和模态显示的屏幕)和 return 到我的主(根)视图控制器。

 self.navigationController?.popToRootViewControllerAnimated(true)

感谢您的帮助!

您需要关闭呈现的模型,然后才能弹出所有推送的视图控制器。呈现的模型不会在导航堆栈中。

self.dismissViewControllerAnimated(true, completion: {});

然后你可以弹出到基础视图控制器。

self.navigationController.popViewControllerAnimated(true);

如果你用presentViewController,你可以用

[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];

返回根视图。它适用于 IOS9.

在 Swift 3 这将起作用:

self.dismiss(animated: true, completion: {});
self.navigationController?.popViewController(animated: true);

Swift 4

self.dismiss(animated: true, completion: {});
self.navigationController?.popViewController(animated: true);