Как вызвать функцию, когда Ok нажата в UIAlert
Я пытаюсь просто вызвать функцию под названием "GoToNewShoot". Когда пользователь нажимает кнопку "ok", когда появляется предупреждение, спасибо!.
код:
@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)
Ответы
Ответ 1
Вы можете сделать это, используя обработчик из 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")
}
Ответ 2
alerty.addAction(UIAlertAction(title: "Just Checking",
style: UIAlertActionStyle.Default,
handler: {(alert: UIAlertAction!) in print("Are You Sure You Want to Start over")}))