以下内容不起作用:
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"windows"
options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
context:NULL];
与此同时,在观察者端:
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"never reached!");
}
有什么线索吗?
注意我的 super 目标是在显示(系统生成的)UIAlertView 时收到通知。
最佳答案
self 回答...
检测何时显示任意 UIAlertView 的正确方法是使用 NSNotificationCenter:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeVisible:) name:UIWindowDidBecomeVisibleNotification object:nil];
然后,在里面:
- (void) windowDidBecomeVisible:(NSNotification*)notification {}
检查有问题的 UIWindow(可通过 notification.object 访问)是否包含作为 UIAlertView 实例的 subview
关于iphone - UIApplication 的 "windows"值上的 KVO?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2847649/