【问题标题】:Pausing UIBar button segue暂停 UIBar 按钮 segue
【发布时间】:2022-07-04 23:23:15
【问题描述】:

我有一个包含多个选项卡栏项目的应用程序,在一个特定屏幕中,如果用户单击另一个栏按钮选项卡,我会尝试停止一些正在运行的功能(因为我只想仔细检查它们是否真的是他们想要做的)。问题是当用户单击另一个选项卡栏按钮时,屏幕会转到该视图控制器,然后显示警报。

有没有办法暂停它,以便仅在用户解决警报后才发生转场?

override func viewDidDisappear(_ animated: Bool) {
        //asking if want to cancel the workout?
        let alert = UIAlertController(title: "Leaving?", message: "The data wont be saved if you leave now, are you sure you want to leave?", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "Yes", style: UIAlertAction.Style.default, handler: nil))
        alert.addAction(UIAlertAction(title: "No", style: UIAlertAction.Style.default, handler: nil))
        self.present(alert, animated: true, completion: nil
}

【问题讨论】:

    标签: ios swift uialertcontroller


    【解决方案1】:

    您应该在执行操作时显示警报控制器,因为当 vc 即将关闭/隐藏时调用 viewDidDisappear,然后在警报控制器的 yes 按钮处理程序中执行 segue 操作

    func askLeaving() {
        // asking if want to cancel the workout?
        let alert = UIAlertController(title: "Leaving?", message: "The data wont be saved if you leave now, are you sure you want to leave?", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "Yes", style: UIAlertAction.Style.default) {
            self.performSegue(withIdentifier:"",sender:nil)
        }
        alert.addAction(UIAlertAction(title: "No", style: UIAlertAction.Style.default, handler: nil))
        self.present(alert, animated: true, completion: nil) 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多