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

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

新規登録して質問してみよう
ただいま回答率
85.50%
Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

Xcode

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

Q&A

解決済

1回答

628閲覧

iOS11.1のみalertControllerの「はい」「いいえ」が反応しない

退会済みユーザー

退会済みユーザー

総合スコア0

Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

Xcode

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

0グッド

0クリップ

投稿2017/11/02 03:07

###前提・実現したいこと
alertControllerの「はい」「いいえ」が押されるまで待機させたい

###発生している問題・エラーメッセージ
iOS11.1のみalertControllerの「はい」「いいえ」が押せない(反応しない)

ボタンのタップからだと反応するが、UITapGestureRecognizerを利用した場合に
反応しなくなる。
また、UICollectionViewのdidSelectItemAtIndexPath内でも同様に反応しない。

iOS11.0だと動作する。

###該当のソースコード

- (void)viewDidLoad { [super viewDidLoad]; UITapGestureRecognizer *viewRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnButtonViewTapped:)]; [self.ButtonView addGestureRecognizer:viewRecognizer]; } /** ボタンタップ時は「はい」「いいえ」が押せる */ - (IBAction)Button_Tap:(UIButton *)sender { __block BOOL isFin = NO; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Confirm" message:@"FIN?" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"はい" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { isFin = YES; }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"いいえ" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { isFin = YES; }]]; [self presentViewController:alertController animated:YES completion:nil]; while (isFin == NO) { [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5f]]; } NSLog(@"Fin"); } /** UITapGestureRecognizerからだと「はい」「いいえ」が押せない。 */ - (void)OnButtonViewTapped:(UITapGestureRecognizer *)recognizer { __block BOOL isFin = NO; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"ConfirmRecognizer" message:@"FIN?" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"はい" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { isFin = YES; }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"いいえ" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { isFin = YES; }]]; [self presentViewController:alertController animated:YES completion:nil]; while (isFin == NO) { [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5f]]; } NSLog(@"Fin"); }

###試したこと
・UIAlertActionのstyleを他のものに変更しても改善しない
・下記のように変更しても改善しない

[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5f]]; ↓ [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; [self presentViewController:alertController animated:YES completion:nil]; ↓ [self presentViewController:alertController animated:YES completion:nil]; [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5f]];

よろしくお知恵をお貸しくださいm(_ _)m

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

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

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

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

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

fuzzball

2017/11/02 04:01

なぜhandlerの中で presentViewController:animated:completion: を呼ばないのでしょうか?
退会済みユーザー

退会済みユーザー

2017/11/02 04:11

[self presentViewController:alertController animated:YES completion:nil];のことでしょうか?Whileの上で呼んでいますが、ここではダメだということでしょうか?
fuzzball

2017/11/02 04:27

すみません、見間違いでした。忘れて下さい。その下で、「はい/いいえ」が押されるまで「無理やり」処理を止めているのはなぜでしょうか?
退会済みユーザー

退会済みユーザー

2017/11/02 04:29

ソースはミニマムで書いていますが、実際にはこのあとで処理が続いていきます。「はい」の場合は処理が続き「いいえ」の場合はreturnしています。
fuzzball

2017/11/02 04:39

「はい/いいえ」の処理は、それぞれのhandlerの中に書きます。無理やり処理を止める必要はありません。
退会済みユーザー

退会済みユーザー

2017/11/02 04:55

それは分かっているのですが、現状のソースを大幅に変更する必要があり、既存のソースのまま動作させたいと考えています。
guest

回答1

0

ベストアンサー

fuzzballさんのご指摘の通り「handler」の中に直接処理を書くことにしました。
ひとつのイベントの中で2回「はい」「いいえ」の選択を表示しているので
別途メソッドを用意して対応することにしました。

ありがとうございました。

- (void)OnButtonViewTapped:(UITapGestureRecognizer *)recognizer { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Confirm" message:@"FIN?" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"はい" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self execute]; }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"いいえ" style:UIAlertActionStyleDefault handler:nil]]; [self presentViewController:alertController animated:YES completion:nil]; } - (void) execute { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Confirm" message:@"FIN?" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"はい" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self execute2]; }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"いいえ" style:UIAlertActionStyleDefault handler:nil]]; [self presentViewController:alertController animated:YES completion:nil]; } - (void) execute2 { }

投稿2017/11/06 04:39

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問