iPhone:检测UIAlert / UIActionSheet是否打开 [英] iPhone: detecting if a UIAlert/UIActionSheet are open

查看:126
本文介绍了iPhone:检测UIAlert / UIActionSheet是否打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iOS应用程序中,我有一个计时器启动,当它启动时,我需要能够检测是否有一个Alert(UIAlertView)或一个Action Sheet(UIActionSheet)打开。

In my iOS application, I have a timer firing up, and when it fires, I need to be able to detect whether there's an Alert (UIAlertView) or an Action Sheet (UIActionSheet) open.

一种方法是修改提示警报/动作表的代码 - 但不幸的是,在我的情况下这不是一个选项。

One way would be to modify the code presenting the alerts/actionsheets - but unfortunately this is not an option in my case.

所以,问题是 - 有没有办法知道/检测警报或行动表是否已被打开?

So, the question is - is there a way of knowing/detecting whether an alert or action sheet have been opened?

是否有任何通知在开启或任何遍历时发送查看层次结构以检测它?

Is there any notifications sent upon opening, or any traversal of the view hierarchy to detect it?

谢谢

推荐答案

他们发送打开时发出警报,但仅限于委托 - 检查这个问题可以解决这个问题。 Techzen建议您在打开警报时将布尔标志设置为 YES ,并在解雇时将其设置回警告。

They do send an alert when they open, but only to their delegate -- Check this question for a nice approach to that problem. Techzen recommends setting a boolean flag to YES when you open up the alert, and setting it back to NO when you dismiss the alert.

编辑:

由于您根本无法访问代码,为什么不试试这段笨重的代码:

Since you don't have access at all to the code, why not try this clunky piece of code:

-(BOOL) doesAlertViewExist {
  for (UIWindow* window in [UIApplication sharedApplication].windows) {
    NSArray* subviews = window.subviews;
    if ([subviews count] > 0) {

      BOOL alert = [[subviews objectAtIndex:0] isKindOfClass:[UIAlertView class]];
      BOOL action = [[subviews objectAtIndex:0] isKindOfClass:[UIActionSheet class]];

      if (alert || action)
        return YES;
     }
  }
  return NO;
}

这篇关于iPhone:检测UIAlert / UIActionSheet是否打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆