【发布时间】:2023-03-04 10:28:01
【问题描述】:
我试图了解我的应用程序的一个奇怪行为,这是一个描述(在一个简单的项目中测试)。
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 上)。您可以根据需要执行多次...
这是错误:当出现警报时,如果您在外部单击两次(足够快,大约 0.2 秒的间隔),警报就会消失并且 ViewControllerB 被关闭。最后,我们可以看到 ViewControllerA,但我们从未要求过它。
还有一个警告信息:
Warning: Attempt to dismiss from view controller <UIViewController: 0x7f85ab633f70> while a presentation or dismiss is in progress!
感谢您的帮助。
【问题讨论】:
-
你能把你的简单测试项目上传到 github 或类似的吗?我真的很想测试一下。
-
我从不在我项目的任何地方打电话给
dismissViewControllerAnimated:completion。 -
当我一次单击两个操作时,在我的代码上观察到相同的行为。例如,单击取消并同时单击外部。你有解决这个问题的办法吗?
标签: ios objective-c uialertcontroller