【发布时间】:2020-02-28 22:16:14
【问题描述】:
我正在显示这样的警报:
self.connectingAlert = [UIAlertController
alertControllerWithTitle:@""
message:NSLocalizedString(@"CONNECTING", nil)
preferredStyle:UIAlertControllerStyleAlert];
[self.connectingAlert addAction:[UIAlertAction
actionWithTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
[self cancelRequest];
}]];
[self presentViewController:self.connectingAlert animated:TRUE completion:nil];
然后我想像这样以编程方式关闭警报:
[self dismissViewControllerAnimated:FALSE completion:nil];
dismiss 代码在 iOS 中运行良好,但在 Mac Catalyst 中没有任何作用。这可能与警报显示为应用程序窗口的一部分(在应用程序之外)以及显示样式被忽略这一事实有关。但我希望驳回方法仍会影响 Mac 警报。
我试过这个以确保一切都正确连接:
UIViewController *test1 = self.connectingAlert.presentingViewController;
UIViewController *test2 = self.connectingAlert.presentingViewController.presentedViewController;
test1 返回视图控制器所属的导航控制器,这看起来很奇怪,但它在 iOS 上做同样的事情。 test2 返回我的警报。只是为了确保,我尝试了这段代码,但它也不起作用:
[self.connectingAlert.presentingViewController dismissViewControllerAnimated:FALSE completion:nil];
有人有这方面的经验吗?我在documentation 中没有看到任何关于它的信息。
【问题讨论】:
标签: ios uialertcontroller mac-catalyst