如果已显示警报,则显示UIAlertController

编程入门 行业动态 更新时间:2024-10-26 10:41:08
本文介绍了如果已显示警报,则显示UIAlertController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

遗留的 UIAlertView 与新的 UIAlertController 之间的区别在于后者需要呈现在特定的viewcontroller上使用 presentViewController:animated:completion:。这给我的用例带来了一个尴尬的问题:当第二个视图控制器出现时,如果已经有 UIAlertController 显示(例如评级对话框)(例如,由于网络连接失败)。我经历过,在这种情况下,第二个 UIAlertController 只是没有显示。

Difference between the legacy UIAlertView and the new UIAlertController is that the latter needs to be presented onto a specific viewcontroller with presentViewController:animated:completion:. This poses an awkward problem for my use case: what if there is already an UIAlertController showing (e.g. a rating dialog) when a second viewcontroller gets presented (e.g. an error dialog due to failed network connection). I have experienced that in this case the second UIAlertController just does not show.

编辑:目前我尝试为了显示警报,我不知道目前是否有任何呈现。

At the moment I try to show an alert, I do not know if there currently is anything presenting.

你如何应对这种情况?

推荐答案

我找到了一个解决方法,找出我可以提出警报的视图控制器。我还发布了这里的答案:

I found a workaround to find out which viewcontroller I can present the alert upon. I also posted the answer here:

@implementation UIViewController (visibleViewController) - (UIViewController *)my_visibleViewController { if ([self isKindOfClass:[UINavigationController class]]) { // do not use method visibleViewController as the presentedViewController could beingDismissed return [[(UINavigationController *)self topViewController] my_visibleViewController]; } if ([self isKindOfClass:[UITabBarController class]]) { return [[(UITabBarController *)self selectedViewController] my_visibleViewController]; } if (self.presentedViewController == nil || self.presentedViewController.isBeingDismissed) { return self; } return [self.presentedViewController my_visibleViewController]; } @end // To show a UIAlertController, present on the following viewcontroller: UIViewController *visibleViewController = [[UIApplication sharedApplication].delegate.window.rootViewController my_visibleViewController];

更多推荐

如果已显示警报,则显示UIAlertController

本文发布于:2023-11-27 16:55:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638834.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   UIAlertController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!