如何从iOS7中的UIWindow对象获取UIAlertView

水鸟隆光

我想制作一个单独的侦听器,每当向用户显示UIAlertView时,它都将捕获UIAlertView。

我首先设置了这个观察者。

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(windowDidBecomeVisible:)
                                                 name:UIWindowDidBecomeVisibleNotification
                                               object:nil];

然后获取如下的UIWindow对象。

- (void)windowDidBecomeVisible:(NSNotification *)notification
{
    UIWindow *window = [notification object];
}

但是从这个窗口对象,我无法获得UIAlertView。该窗口下只有一个子视图,该子视图没有任何子视图。

下面的链接显示了从window对象获取UIAlertView对象的代码,但这不起作用。https://stackoverflow.com/a/2529692/1709287

也许iOS7做了一些技巧来包装和隐藏UIAlertView。有谁知道如何跟踪UIWindow对象的子视图(或成员)以到达当前显示在屏幕上的UIAlertView对象?

拉杰什

在iOS 7中,您可能无法获取“alerview通过”窗口的实例您将必须在应用程序中的某些位置显式保存引用。

我们面临着同样的问题。问题已解决

1)将UIAlertView话语归类MYAlertview

2)在AppDelegate中具有MyAlertView的属性(您可以选择任何实例)

3)覆写show:方法

- (void)Show{
  AppDelegate *appdelegate = (AppDelegate)[[UIApplication SharedApplication] delegate];
  if([[appdelegate alertView] isVisible])
  [[appdelegate alertView] dismissWithClickedButtonIndex:0 animated:NO]; //We have requirement like dismissing you can have any operation here

  [appDelegate setAlertView:self];
}

4)更换所有的UIAlertViewMYAlertview

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章