无需参考即可查找 UIAlertView iOS 7 [英] Find UIAlertView without having reference to it iOS 7
问题描述
我在我的项目中使用了一个代码片段,在这里回答:UIAlertView而没有参考它
I was using a code snippet in my project answered here: UIAlertView without having reference to it
代码如下:
+ (UIAlertView *) getUIAlertViewIfShown {
if ([[[UIApplication sharedApplication] windows] count] == 1) {
return nil;
}
UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
if ([window.subviews count] > 0) {
UIView *view = [window.subviews objectAtIndex:0];
if ([view isKindOfClass:[UIAlertView class]]) {
return (UIAlertView *) view;
}
}
return nil;
}
不幸的是,它在 iOS 7 中不起作用,我无法关闭警报视图.在调试时,我发现在循环中它显示该视图属于 UITransitionView
类.非常令人困惑,因为我找不到有关此视图类的任何快速文档.
Unfortunately its not working in iOS 7 and I'm unable to dismiss an alert view. While debugging I found that in the loop its showing that view is of class UITransitionView
. Pretty confusing because I couldn't find any quick documentation for this view class.
有什么想法可以解决这个问题吗?
Any ideas how can I fix this problem?
推荐答案
在iOS7中,UIAlertView
窗口不会出现在-[UIApplication windows]
中.事实上,UIAlertView
本身从来没有被添加到任何窗口中,-[UIAlertView window]
总是nil
.相反,警报视图管理放置在 -[UIApplication keyWindow]
中的各种未记录的视图,而不引用回警报视图.
In iOS7, the UIAlertView
window does not appear in -[UIApplication windows]
. In fact, the UIAlertView
itself is never added to any window, -[UIAlertView window]
is always nil
. Instead, the alert view manages a variety of undocumented views placed in -[UIApplication keyWindow]
with no reference back to the alert view.
您在 iOS7 中唯一真正的选择是实际跟踪您的警报视图.
Your only real option in iOS7 is to actually keep track of your alert views.
这篇关于无需参考即可查找 UIAlertView iOS 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!