###前提・実現したいこと
Bar Button Itemの "保存"を押した際の動作をコードで書いています。
UIAlertControllerでメッセージボックスを表示し、確認動作を実装したいのですが、
メッセージを開いてOKを押すとそこで終わってしまいます。
スコープ内を最後まで実行するにはどうしたらよいでしょうか?
よろしくお願いします。
###該当のソースコード
@IBAction func hozon(sender: AnyObject) {
//入力不備があったらメッセージ表示 if(kakunin.text != "OK") { //項目欄に不備があった時のメッセージの関数を呼ぶ self.errorAlert() return } //確認メッセージの関数を呼ぶ self.alert() //何らかの方法(今後作成予定)で保存後、前の画面に戻る self.navigationController?.popViewControllerAnimated(true) }
//項目欄に不備があった時のメッセージの関数
func errorAlert(){
//エラーメッセージ
let alertController:UIAlertController = UIAlertController(title: "エラー", message: "項目内容を確認してください。", preferredStyle: .Alert)
let actionCancel = UIAlertAction(title: "OK", style: .Cancel){ action in
}
alertController.addAction(actionCancel)
// UIAlertの起動 presentViewController(alertController, animated: true, completion: nil) } //確認メッセージの関数 func alert(){ //確認メッセージ let alertController:UIAlertController = UIAlertController(title: "確認", message: "保存します。よろしいですか?", preferredStyle: .Alert) let actionCancel = UIAlertAction(title: "Cansel", style: .Cancel){ action in UIFont.boldSystemFontOfSize(UIFont.labelFontSize())} let actionOK = UIAlertAction(title: "OK", style: .Default){ action in } alertController.addAction(actionCancel) alertController.addAction(actionOK) // UIAlertの起動 presentViewController(alertController, animated: true, completion: nil) }
###試したこと
let actionOK = UIAlertAction(title: "OK", style: .Default){ action in
/*return*/ //これでは戻らなかった。 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/15 05:10
2016/08/15 05:19
2016/08/15 07:30