iPhone:检测 UIAlert/UIActionSheet 是否打开
在我的 iOS 应用程序中,我启动了一个计时器,当它启动时,我需要能够检测是否有警报 (UIAlertView) 或操作表 (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?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
他们在打开时确实会发送警报,但仅限于他们的
代表
- 检查这个问题 是解决该问题的好方法。 Techzen 建议在您打开警报时将布尔标志设置为YES
,并在您关闭警报时将其设置回NO
。编辑:
既然您根本无权访问代码,为什么不尝试这段笨重的代码:
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 toYES
when you open up the alert, and setting it back toNO
when you dismiss the alert.EDIT:
Since you don't have access at all to the code, why not try this clunky piece of code:
您还可以检查视图的窗口属性:
You can also check for the view's window property:
检测警报似乎相对容易,但操作表却让我难住了。在 iOS 6.1 中我必须更进一步
}
}
Detecting alerts seems relatively easy, but action sheets had me stumped. In iOS 6.1 I had to go one step further
}
}
感谢您的帮助,但从 iOS 6 开始,该代码段不再起作用。
不过,我用这段代码解决了这个问题。希望这有帮助
thanx for the help, but since iOS 6, the code piece doesn't work anymore.
However, I fixed the issue with this code. Hope this helps