解雇ios 7中的UIAlertView不起作用? [英] Dismissing a UIAlertView in ios 7 not working?

查看:66
本文介绍了解雇ios 7中的UIAlertView不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在显示另一个之前解雇UIAlertView,我在这里找到答案:
iOS解雇UIAlertView正在显示另一个

I'm trying to dismiss a UIAlertView before showing another and I found the answer here: iOS dismiss UIAlertView beforing showing another

问题是这不适用于iOS7但适用于iOS6。

The problem is that this is not working on iOS7 but works on iOS6.

这适用于iOS6

-(void)closePreviousAlert{
for (UIWindow* w in [UIApplication sharedApplication].windows)
    for (NSObject* o in w.subviews)
        if ([o isKindOfClass:[UIAlertView class]])
            [(UIAlertView*)o dismissWithClickedButtonIndex:[(UIAlertView*)o cancelButtonIndex] animated:YES];
}

还有其他解决方案吗?

推荐答案

而不是使用你的O(n ^ 2)方法关闭警报,它可能会更轻量级(和iOS 7有效)为您创建私有属性通过合成的getter警告和引用并解除它们。此外,我不时在alertview上设置一个标签,并通过其标签引用它作为一个快速而肮脏的解决方案。

Rather than using your O(n^2) approach to close the alert, it would probably be more lightweight (and iOS 7 valid) to create private properties for your alerts and reference and dismiss them via their synthesized getters. Also, I have from time to time set a tag on the alertview and referenced it via its tag as a quick and dirty solution.

如果这些解决方案中的任何一个对于您的应用程序的上下文来说太简单,我可能会建议您重新考虑使用alertviews。太多的应用滥用了警报视图,在我看来,他们应该谨慎使用非常 - 只是添加一些未经请求的反馈:)。

If either of these solutions are too simple for the context of your application I might suggest rethinking your use of alertviews. Too many apps abuse alertviews and in my opinion they should be used very sparingly - just to add some unsolicited feedback :).

另一种方法这可以帮助你在完成alertview的生命时实现基于块的回调。请参阅使用块简化UIAlertView

A different approach that could help you is to implement a block-based callback upon completion of the alertview's life. See Simplify UIAlertView with Blocks.

这篇关于解雇ios 7中的UIAlertView不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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