我尝试简单地调用一个名为“GoToNewShoot”的函数当用户按下“确定”按钮时弹出警报谢谢!
代码:
@IBAction func GobacktoCamera(sender: AnyObject) {
var alertController = UIAlertController(title: "Just Checking", message: "Are You Sure You Want to Start over ", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
最佳答案
您可以通过使用 addAction
中的处理程序来完成此操作:
@IBAction func GobacktoCamera(sender: AnyObject) {
var alertController = UIAlertController(title: "Just Checking", message: "Are You Sure You Want to Start over", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Yes", style: .Default, handler: { action in
//run your function here
self.GoToNewShoot()
}))
self.presentViewController(alertController, animated: true, completion: nil)
}
func GoToNewShoot(){
println("Method Called")
}
关于swift - 在 UIAlert 中按下 Ok 时如何调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32535495/