質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
iOS 9

iOS 9は、アップル社のモバイルOSであるiOSシリーズのバージョン。特徴として検索機能の強化、Siriの機能改良、iPad向けマルチタスクなどがあります。マルチウィンドウ機能をサポートし、iPad向けマルチタスクもサポートされています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

1491閲覧

swift xcode iOS

退会済みユーザー

退会済みユーザー

総合スコア0

iOS 9

iOS 9は、アップル社のモバイルOSであるiOSシリーズのバージョン。特徴として検索機能の強化、Siriの機能改良、iPad向けマルチタスクなどがあります。マルチウィンドウ機能をサポートし、iPad向けマルチタスクもサポートされています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2016/11/12 14:50

編集2016/11/12 15:06

if文の評価結果によりUIAlertControllerを表示するコードを書いたのですが、時に二回,さんかい連続で表示する場合などはif文を評価してくれません。なので、本来はそうはしたくないのですが、一つのアラートが表示されている上にもう一つのアラートが表示されてしまいます。

いろいろ調べたら
連続で表示するときは、その都度親ビューコントローラを取得すればいいとのことだったのですが、
swiftでの表記が少なく見様見真似でのコードになってしまいました。どのように変更したらいいでしょうか。

Swift

1 2 func judge(){ 3 4 // ① UIAlertControllerクラスのインスタンスを生成 5 let alert: UIAlertController = UIAlertController(title:OK, message:OK, preferredStyle:.alert) 6 // ② Actionの設定 7 // OKボタン 8 let cancelAction: UIAlertAction = UIAlertAction(title: "OK", style:.default,handler:{ 9 // ボタンが押された時の処理を書く(クロージャ実装) 10 (action:UIAlertAction!) -> Void in 11 }) 12 13 // ③ UIAlertControllerにActionを追加 14 alert.addAction(cancelAction) 15 16 // ④ Alertを表示 17 var baseview:UIViewController = UIApplication.shared.keyWindow!.rootViewController! 18 while(baseview.presentedViewController != nil && !baseview.presentedViewController!.isBeingDismissed){ 19 baseview=baseview.presentedViewController! 20 } 21 baseview.present(alert5, animated: true, completion: nil) 22 23 } 24 25@IBAction func OKTouch(_ sender: UIButton) { 26 //aが3でないならアラート0表示 27 if(a != 3){ 28 29 // ① UIAlertControllerクラスのインスタンスを生成 30 let alert: UIAlertController = UIAlertController(title:OK, message:OK, preferredStyle:.alert) 31 // ② Actionの設定 32 // OKボタン 33 let cancelAction: UIAlertAction = UIAlertAction(title: "OK", style:.default,handler:{ 34 // ボタンが押された時の処理を書く(クロージャ実装) 35 (action:UIAlertAction!) -> Void in 36 }) 37 38 // ③ UIAlertControllerにActionを追加 39 alert.addAction(cancelAction) 40 41 // ④ Alertを表示 42 var baseview:UIViewController = UIApplication.shared.keyWindow!.rootViewController! 43 while(baseview.presentedViewController != nil && !baseview.presentedViewController!.isBeingDismissed){ 44 baseview=baseview.presentedViewController! 45 } 46 baseview.present(alert5, animated: true, completion: nil) 47 48 //aが3でない時、かつが3でない時アラート1表示 49 if(b != 3){ 50 51 // ① UIAlertControllerクラスのインスタンスを生成 52 let alert1: UIAlertController = UIAlertController(title:OK, message:OK, preferredStyle:.alert) 53 // ② Actionの設定 54 // OKボタン 55 let cancelAction: UIAlertAction = UIAlertAction(title: "OK", style:.default,handler:{ 56 // ボタンが押された時の処理を書く(クロージャ実装) 57 (action:UIAlertAction!) -> Void in 58 }) 59 60 // ③ UIAlertControllerにActionを追加 61 alert1.addAction(cancelAction) 62 63 // ④ Alertを表示 64 var baseview:UIViewController = UIApplication.shared.keyWindow!.rootViewController! 65 while(baseview.presentedViewController != nil && !baseview.presentedViewController!.isBeingDismissed){ 66 baseview=baseview.presentedViewController! 67 } 68 baseview.present(alert1, animated: true, completion: nil) 69 } 70 } 71 72 judge() 73} 74

エラー

Warning: Attempt to present <one.thirdViewController: 0x7fb1f05d9b70> on <one.secondViewController: 0x7fb1f0888800> which is already presenting <UIAlertController: 0x7fb1f073ed70>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

一つのアラートが表示されている上にもう一つのアラートが表示されてしまいます

2枚目以降のbaseViewはアラートなのでそうなると思います。
部品の性質上、連続で出すならアラートアクションで次のアラートに繋げる形にするほうがよいと思います。
同期処理の話とはちょっと違うかなと。

投稿2016/11/12 17:39

編集2016/11/12 17:56
fromageblanc

総合スコア2724

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2016/11/13 04:48

ビューが開いてたら 新しいビューは表示しないようには出来ませんかね?やはりアクションで二つ目を表示しないといけないんでしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問