【问题标题】:Dismiss View Controller from Modal从模态中关闭视图控制器
【发布时间】:2017-05-12 12:15:38
【问题描述】:

我有一个带有多个控制器的MainTabBarController。 在我的FirstTabViewController(嵌入UINavigationController)中,我推送到另一个视图控制器,例如:navigationController?.pushViewController(secondViewController, animated: true)

在这个控制器中,我要展示一个模态视图控制器,例如:

let vc = self.storyboard!.instantiateViewController(withIdentifier: "SomeViewController") as! SomeViewController

vc.modalPresentationStyle = .overFullScreen
vc.modalTransitionStyle = .coverVertical

let nav = UINavigationController(rootViewController: vc)
self.present(nav, animated: true, completion: nil)

SomeViewController 中,我必须像这样关闭这个控制器:self.dismiss(animated: true),但它会自动弹出到根视图控制器 (FirstTabViewController)。

我的问题,为什么?

谢谢。

【问题讨论】:

    标签: ios swift dismiss navigationcontroller


    【解决方案1】:

    在您当前的控制器上而不是在navigationController 上显示SomeViewController

    所以换行了:

    self.navigationController?.present(nav, animated: true, completion: nil)
    

    收件人:

    self.present(nav, animated: true, completion: nil)
    

    【讨论】:

    • @Idnext 当你这样呈现时,当你关闭 SomeViewController 时发生了什么?
    • FirstTabViewController 出现......就像一个 popToRoot 效果
    • @Idnext 你确定从 firstViewController 到 SecondController 你正在使用 pushViewController 移动,因为看起来你也在展示 secondViewController 而不是 push
    • @Idnext 尝试评论这两行 vc.modalPresentationStyle = .overFullScreen vc.modalTransitionStyle = .coverVertical 并现在检查它是否正确解散?
    【解决方案2】:

    _ = navigationController?.popViewController(animated: true)

        dismiss(animated: true, completion: nil)
    

    【讨论】:

      猜你喜欢
      • 2013-01-01
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多