我是iOS新手.我正在开发一个包含notification的应用程序.当通知到达时使用应用程序显示alertView.一切正常但如果通知到达时另一个alertView已经显示问题则启动.Notification alertView显示在上面现有alertView.当我点击确定通知alertView UI导航到新的视图控制器,然后第一个alertView仍然显示.如果我点击该alertView我的应用程序崩溃.
当我点击通知alertView时,有没有办法关闭显示的所有警报视图.
我有这个解决方案
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];
}
Run Code Online (Sandbox Code Playgroud)
但是此代码适用于iOS6而非iOS7.我想在iOS7中使用相应的代码.
谁能请帮忙.谢谢
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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
279 次 |
| 最近记录: |