本文介绍了iOS解雇UIAlertView正在展示另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Utils类,当触发某些通知时会显示UIAlertView。有没有办法在显示新的UIAlertViews之前解雇任何打开的UIAlertViews?
I have a Utils class which shows UIAlertView when certain notifications are triggered. Is there a way to dismiss any open UIAlertViews before showing a new one?
当我的应用程序使用
[self checkViews:application.windows];
在applicationDidEnterBackground上
on applicationDidEnterBackground
- (void)checkViews:(NSArray *)subviews {
Class AVClass = [UIAlertView class];
Class ASClass = [UIActionSheet class];
for (UIView * subview in subviews){
if ([subview isKindOfClass:AVClass]){
[(UIAlertView *)subview dismissWithClickedButtonIndex:[(UIAlertView *)subview cancelButtonIndex] animated:NO];
} else if ([subview isKindOfClass:ASClass]){
[(UIActionSheet *)subview dismissWithClickedButtonIndex:[(UIActionSheet *)subview cancelButtonIndex] animated:NO];
} else {
[self checkViews:subview.subviews];
}
}
}
这使得applicationDidEnterBackground变得简单因为我可以使用application.windows
This makes it easy on applicationDidEnterBackground as I can use application.windows
我可以使用AppDelegate或类似的东西来获取所有视图,循环它们并关闭任何UIAlertViews吗?
Can I use the AppDelegate or anything similar to get all the views, loop through them and dismiss any UIAlertViews?
推荐答案
for (UIWindow* window in [UIApplication sharedApplication].windows) {
NSArray* subviews = window.subviews;
if ([subviews count] > 0)
if ([[subviews objectAtIndex:0] isKindOfClass:[UIAlertView class]])
[(UIAlertView *)[subviews objectAtIndex:0] dismissWithClickedButtonIndex:[(UIAlertView *)[subviews objectAtIndex:0] cancelButtonIndex] animated:NO];
}
这篇关于iOS解雇UIAlertView正在展示另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!