在没有引用iOS 7的情况下查找UIAlertView [英] Find UIAlertView without having reference to it iOS 7
问题描述
我在我的专案中使用了程式码片段: UIAlertView参考它
以下是代码:
+(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
。非常混乱,因为我找不到这个视图类的任何快速文档。
任何想法如何解决这个问题?
- [UIApplication windows] / code>。事实上, UIAlertView
本身从不添加到任何窗口, - [UIAlertView window]
总是 nil
。相反,警报视图管理放置在 - [UIApplication keyWindow]
中的各种未记录的视图,而不引用回到警报视图。
iOS7中唯一真正的选项是实际跟踪您的提醒视图。
I was using a code snippet in my project answered here: UIAlertView without having reference to it
Here's the code:
+ (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;
}
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?
解决方案 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.
Your only real option in iOS7 is to actually keep track of your alert views.
这篇关于在没有引用iOS 7的情况下查找UIAlertView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!