解雇ios 7中的UIAlertView不起作用?

编程入门 行业动态 更新时间:2024-10-26 10:35:59
本文介绍了解雇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不起作用?

本文发布于:2023-11-27 20:36:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639510.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   ios   UIAlertView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!