gpt4 book ai didi

ios - 如何从递归 View Controller 返回 Root View Controller (第四)

转载 作者:行者123 更新时间:2023-11-29 05:58:02 24 4
gpt4 key购买 nike

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,不间断)

如果我按下 Controller 中的后退按钮,我必须返回(即firstviewcontroller)

问题是:

在我的代码中它正在运行(即不间断)

我无法按后退按钮返回(即firstviewcontroller)

最佳答案

navigationController?.popViewController(animated: true) 而不是 navigationController?.popToRootViewController(animated: true) 可能是您所需要的,伙计。 (基于您刚刚编辑的内容)

关于ios - 如何从递归 View Controller 返回 Root View Controller (第四),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54955542/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com