2016-03-21 1 views
0

UIAlertControllerが警告を画面に正しく表示していますが、xCodeシミュレータでokを押すとアラートを残さないようにします。 UIAlertActionStyle.CancelUIAlertController addActionが動作しない

func displayAlertMessage(userMessage:String) { 

let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert); 

let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Cancel, handler: nil); 

myAlert.addAction(okAction); 

self.presentViewController(myAlert, animated: true, completion: nil); 

} 

からalert view image

func displayAlertMessage(userMessage:String) { 

    let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert); 

    let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil); 

    myAlert.addAction(okAction); 

    self.presentViewController(myAlert, animated: true, completion: nil); 

} 
+1

に何かをしたい場合は、displayAlertMessageはメインスレッドから呼び出されることを、よろしいですか? – dimpiax

+0

はい私は正しい文字列がユーザメッセージに入力されているためです。 –

+0

ちょうどメモ;外部画像にリンクするのではなく、質問に画像を埋め込むことが望ましい(投稿を作成/編集するときに画像ボタンがある)。 –

答えて

1

変更UIAlertActionStyle.Default、あなたは

OK
let okAction = UIAlertAction(title: "OK", style: .Default) { (action) in 
     //do whatever you want to do here 
    // for e.g dismiss view controller or segue your view controller etc. 
    } 
+0

これらのソリューションのどちらも機能しませんでした。オンラインのドキュメントからは、Alert Controllerを終了するように思えますが、同じビューに戻るので、ハンドラをnilにしておく必要があります。 –

+0

それは仕事でなければなりません。メインスレッドでこれを使用していますか?何を正確にしたいのですか? – Sahil

+0

問題が見つかりました。私はシミュレータでスローモーションを有効にしました。 –

関連する問題