2015-09-12 11 views
6

Mi sforzo di chiamare semplicemente una funzione chiamata "GoToNewShoot" Quando l'utente preme il pulsante "ok" quando compare l'avviso Grazie !.Come chiamare una funzione quando Ok viene premuto in un UIAlert

Codice:

@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) 

risposta

10

è possibile farlo utilizzando handler da addAction questo modo:

@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") 
} 
Problemi correlati