class FourthViewController : UIViewController {
@IBOutlet weak var previousLabel: UILabel!
@IBOutlet weak var backButton: UIButton!
var delegate: FourthToFirst?
var label = ""
// MARK: - Lifecycle method
override func viewDidLoad() {
super.viewDidLoad()
previousLabel.text = label
let fourthViewController = storyboard?.instantiateViewController(withIdentifier: "FourthViewController") as? FourthViewController
navigationController?.pushViewController(fourthViewController!, animated: true)
}
// MARK: - IBAction
@IBAction func backToFirst(_ sender: Any) {
navigationController?.popToRootViewController(animated: true)
}
其实我在fourthviewController中它是递归的(即一次又一次地推动fourthViewcontroller,不停)
如果我按了控制器中的后退按钮,则必须返回(即firstviewcontroller)
问题是:
在我的代码中它正在(即不停)
我无法按返回按钮返回(即firstviewcontroller)
最佳答案
您需要的是navigationController?.popViewController(animated: true)
而不是navigationController?.popToRootViewController(animated: true)
伴侣。 (根据您刚刚编辑的内容)
关于ios - 如何从递归 View Controller 返回根 View Controller (第四),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54955542/