📜  xcode 在导航回屏幕后执行代码 - Swift 代码示例

📅  最后修改于: 2022-03-11 15:01:00.534000             🧑  作者: Mango

代码示例2
// Use this to override the navigation bar's default back button
    override func viewDidLoad {
        super.viewDidLoad()
        self.navigationItem.hidesBackButton = true
        let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.plain, target: self, action: #selector(YourViewController.back(sender:)))
        self.navigationItem.leftBarButtonItem = newBackButton
    }

    @objc func back(sender: UIBarButtonItem) {
        // Perform your custom actions
        // ...
        // Go back to the previous ViewController
        _ = navigationController?.popViewController(animated: true)
    }