アラートがポップアップ表示されたときにユーザーが「OK」ボタンを押すと、「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")
}
alerty.addAction(UIAlertAction(title: "Just Checking",
style: UIAlertActionStyle.Default,
handler: {(alert: UIAlertAction!) in print("Are You Sure You Want to Start over")}))