###前提・実現したいこと
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
なぜhandlerの中で presentViewController:animated:completion: を呼ばないのでしょうか?
[self presentViewController:alertController animated:YES completion:nil];のことでしょうか?Whileの上で呼んでいますが、ここではダメだということでしょうか?
すみません、見間違いでした。忘れて下さい。その下で、「はい/いいえ」が押されるまで「無理やり」処理を止めているのはなぜでしょうか?
ソースはミニマムで書いていますが、実際にはこのあとで処理が続いていきます。「はい」の場合は処理が続き「いいえ」の場合はreturnしています。
「はい/いいえ」の処理は、それぞれのhandlerの中に書きます。無理やり処理を止める必要はありません。
それは分かっているのですが、現状のソースを大幅に変更する必要があり、既存のソースのまま動作させたいと考えています。
回答1件
あなたの回答
tips
プレビュー