警报阻止Segue iOS



在执行segue之前,我想向用户请求权限(我正在使用UIAlert(。一旦他们回答了警报中的问题,我想转到下一个视图控制器,不管他们的回答如何。

代码看起来像这样:

showAlert()        //Method showing the alert
performSegue(withIdentifier : "secondVC", sender : self)

我在这里面临的问题是,应用程序向我显示了警报,但没有执行segue。

在警报的解除按钮中添加一个完成处理程序,如

let alert = UIAlertController(title: "Alert", message: "Content Here", preferredStyle: .alert)
// add textfield or whatever you need
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
self.performSegue(withIdentifier: "secondVC", sender: self)
}))
present(alert, animated: true)

当用户按下警报上的"OK"按钮时,将调用完成处理程序。

最新更新