【问题标题】:How to return to Root View Controller如何返回根视图控制器
【发布时间】:2016-03-23 10:50:31
【问题描述】:

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

首页 -> screen1-> screen2(自定义进度指示器)

我想关闭自定义 progressIndicator(以及模态显示的屏幕)并一次返回我的主页(根)视图控制器。

 self.navigationController?.popToRootViewControllerAnimated(true)

感谢您的帮助!

【问题讨论】:

    标签: ios swift navigation


    【解决方案1】:

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

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

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

    self.navigationController.popViewControllerAnimated(true);
    

    【讨论】:

      【解决方案2】:

      如果你使用presentViewController,你可以使用

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

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

      【讨论】:

        【解决方案3】:

        斯威夫特 4

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

        【讨论】:

          【解决方案4】:

          在 Swift 3 中这将起作用:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2017-05-26
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-12-11
            • 2013-01-08
            相关资源
            最近更新 更多