【发布时间】:2019-05-11 18:28:33
【问题描述】:
[观看次数]
Main.storyboard - ViewController
↓ 推
Second.storyboard - SecondViewController
↓ 模态
Third.storyboard - ThirdViewController
我一直在尝试从 ThirdViewController → SecondViewController → ViewController 回来
从 ThirdViewController 回到 SecondViewController 就可以了。
// ThirdViewController
@IBAction func tapBackBtn(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
SecondViewController().back()
}
但是 func back() - self.navigationController?.popViewController(animated: true) 不起作用。
// SecondViewController
func back() {
// Come here though...
self.navigationController?.popViewController(animated: true)
}
@IBAction func tapBackBtn(_ sender: Any) {
// It works though...
self.navigationController?.popViewController(animated: true)
}
有没有办法从 Third/SecondViewController 自动返回到 ViewController?
谢谢。
【问题讨论】:
-
第一个问题是:为什么你对一个
ViewController使用不同的故事板?如果可能,则仅在一个情节提要中添加所有 ViewController。它将提供控制器之间的轻松导航:(1. Push to next, 2. Present controller from anywhere, 3. Back to one or back to more than one or back to root controller) -
大家好,谢谢大家。使用不同的故事板来计划项目。我终于在 SecondVC 上使用此代码解决了我的问题。
override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if let presented = self.presentedViewController { if type(of: presented) == ThirdViewController.self { self.back() } } }谢谢