【问题标题】:How to grab UIAlertView from UIWindow object in iOS7如何从 iOS7 中的 UIWindow 对象中获取 UIAlertView
【发布时间】:2014-04-13 03:21:53
【问题描述】:

我想创建一个监听器,只要 UIAlertView 显示给用户,它就会抓取它。

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

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

然后得到 UIWindow 对象,如下所示。

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

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

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

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

【问题讨论】:

    标签: ios objective-c uialertview


    【解决方案1】:

    人们在 iOS 6 中通常会做这种事情。

    Apple 故意让它在 iOS 7 上变得不可能。你不能再这样做了。唯一的选择是私有 API,使用这些 API 会导致您的应用被商店拒绝。

    如果您需要这种级别的控制,您必须停止使用 UIAlertView。

    【讨论】:

      【解决方案2】:

      在iOS 7 中你可能无法通过window.xml 获取alerview 的实例。您必须在应用程序中的某个位置显式保存引用。

      我们遇到了同样的问题。问题已解决

      1) 继承UIAlertViewMYAlertview

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

      3) 覆盖show:method

      - (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) 将所有UIAlertView 替换为MYAlertview

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-14
        • 1970-01-01
        • 2013-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-31
        • 2010-11-17
        相关资源
        最近更新 更多