gpt4 book ai didi

ios - UIAlertController 解雇他的 presentingViewController

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:37:47 26 4
gpt4 key购买 nike

我试图了解我的应用程序的一个奇怪行为,这里是一个描述(在一个简单的项目中测试)。

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!

感谢您的帮助。

最佳答案

我更愿意在您的 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]];
}];

关于ios - UIAlertController 解雇他的 presentingViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26705319/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com