页面先 present 跳转到页面2。这时候我写了一个BUTTON想要 push 到页面3。发现 push 代码不工作,请问我要怎么做才能 push 出去 (没用storyboard,页面都是代码写的)
首先, 页面2是present(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) } }
首先, 页面2是present(modal)出来的, 层次在页面1的navigationController上面, 必须先dismiss页面2, 然后再执行push.
A present B
: