2015-09-12 11 views
6

私は単純に "GoToNewShoot"という関数を呼び出しようとします。警告が表示されたら、ユーザーが "ok"ボタンを押してください。UIAlertで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) 

答えて

10

あなたは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") 
} 
関連する問題