2014-09-05 46 views
9

我是iOS新手。我正在开发一个包含通知的应用程序。当通知到达时使用应用程序显示alertView。一切正常,但如果通知到达时另一个alertView已经显示问题starts.Notification alertView显示在现有alertView上方。当我单击确定通知alertView UI导航到一个新的视图控制器和第一个alertView保持显示。如果我点击该alertView我的应用程序崩溃。如何关闭在iOS7中打开的所有alertviews

当我点击通知alertView时,有什么办法可以关闭所有显示的alertviews。

我得到了这个解决方案

for (UIWindow* window in [UIApplication sharedApplication].windows) 
{ 
    NSArray* subviews = window.subviews; 
    if ([subviews count] > 0) 
    if ([[subviews objec`enter code here`tAtIndex:0] isKindOfClass:[UIAlertView class]]) 
     [(UIAlertView *)[subviews objectAtIndex:0] dismissWithClickedButtonIndex:[(UIAlertView *)[subviews objectAtIndex:0] cancelButtonIndex] animated:NO]; 
} 

但这代码适用于iOS6的不iOS7。 我想在iOS7中的相应代码。

任何人都可以请提前

回答

1
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; 
     [alert1 show]; 
     [self performSelector:@selector(dismiss:) withObject:alert1 afterDelay:1.0]; 

-(void)dismiss:(UIAlertView*)alert 
{ 
    [alert dismissWithClickedButtonIndex:0 animated:YES]; 
} 
+0

感谢bhavik但是这个代码不工作help.Thanks – 2014-09-08 07:07:17

+0

你不能代码的任何特定行关闭所有AlertView。 – bhavik 2014-09-08 13:45:09

相关问题