swift3 页面先 present 跳转之后再 push 的问题

页面先 present 跳转到页面2。这时候我写了一个BUTTON想要 push 到页面3。发现 push 代码不工作,请问我要怎么做才能 push 出去

(没用storyboard,页面都是代码写的)

阅读 5.4k
1 个回答

首先, 页面2present(modal)出来的, 层次在页面1的navigationController上面, 必须先dismiss页面2, 然后再执行push.

A present B:

  • A.presentedViewController就是B;
  • 若A没有navigationController, 那么B.presentingViewController就是A;
  • 若A有navigationController, 那么B.presentingViewController就是navigationController;
// 在页面2的button点击事件中push.
func btnClick() {
    
    guard let nav = self.presentingViewController as? UINavigationController else {
        return
    }
    let vc = ThridViewController()
    dismiss(animated: false) {
        nav.pushViewController(vc, animated: true)
        print(nav.viewControllers)
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进