3

アプリの奇妙な動作を理解しようとしています。ここに説明があります(簡単なプロジェクトでテストされています)。

ViewControllerA はモーダルに表示されています ViewControllerB

ViewControllerB にはボタンが含まれています。このボタンは、この方法で指定された UIAlertController を提示しています

alert = [UIAlertController alertControllerWithTitle:@"Test" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"Action" style:UIAlertActionStyleDefault handler:^(UIAlertAction *handler) { NSLog(@"Action"); }]];

ViewControllerB はこの方法でアラートを提示しています

- (IBAction)button:(id)sender {
alert.popoverPresentationController.sourceView = self.button;
alert.popoverPresentationController.sourceRect = self.button.bounds;
[self presentViewController:alert animated:YES completion:nil];
}

これで、ボタンをクリックするとアラートが表示され、アラートの外側をクリックするとアラートが消えます (私は iPad を使用しています)。何度でもできる...

バグは次のとおりです。アラートが表示されているときに、外側を 2 回クリックすると (すぐに ~0.2 秒間隔で)、アラートが消え、ViewControllerB が破棄されます。最後に ViewControllerA が表示されますが、それを求めたことはありません。

次の警告メッセージもあります。

Warning: Attempt to dismiss from view controller <UIViewController: 0x7f85ab633f70> while a presentation or dismiss is in progress!

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

4

1 に答える 1

0

UIAlertController の最後に UITapGestureRecognizer を追加したいと思います。お気に入り :

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Test"
                                                                         message:@"Test Message."
                                                                  preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *closeAction = [UIAlertAction actionWithTitle:@"Close"
                                                      style:UIAlertActionStyleDefault
                                                    handler:nil];

UIAlertAction *someAction = [UIAlertAction actionWithTitle:@"Action"
                                                       style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * _Nonnull action) {
                                                         ....
                                                     }];
[alertController addAction:closeAction];
[alertController addAction:someAction];
[self presentViewController:alertController animated:YES completion:^{
    [alertController.view.superview addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget: self action:nil]];
}];
于 2015-12-31T19:15:44.323 に答える