【问题标题】:how to dismiss current presenting controller and navigate to other controller using navigation controller?如何关闭当前呈现控制器并使用导航控制器导航到其他控制器?
【发布时间】:2019-10-09 11:49:02
【问题描述】:
self.dismiss(animated: false) {
  let vc = self.storyboard?.instantiateViewController(withIdentifier: "ViewController") as! ViewController
  self.navigationController?.pushViewController(vc, animated: false)
}

【问题讨论】:

    标签: ios swift presentviewcontroller navigationcontroller


    【解决方案1】:

    self.navigationController 只有在您的 ViewController 嵌入 UINavigationController 时才会有一个值,否则它将为零。 在您的情况下,它为零,因此您的控制器已成功关闭,但 ViewController 未推送。

    在您的完成块中,使用 self.presentingViewController 推送对象。

    self.dismiss(animated: false) {
      let vc = self.storyboard?.instantiateViewController(withIdentifier: "ViewController") as! ViewController
      self.presentingViewController?.navigationController?.pushViewController(vc, animated: false)
    }
    

    【讨论】:

    • 那不行。当前控制器关闭但不导航到其他控制器
    • 只需打印(self.presentingViewController?.navigationController) 并检查它是否有值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-09
    • 2020-07-14
    • 1970-01-01
    相关资源
    最近更新 更多