如何在alertview中选择取消按钮时从数组中关闭所有alertview?我在一个数组中有5个alertview ..如果我从第一个alertview选择取消,那么它将需要关闭剩余的所有警报而不是显示。
for (NSDictionary *temp in [RMUserDefaults userDetails].SharedFolders)
{
NSString *name = temp[@"Name"];
sharedFolderId = [RMUserDefaults userDetails].SharedFolders[0][@"id"];
alert1= [[CustomUIAlertView alloc]initWithTitle:LString(@"RECEIPT_MATCH") message:[NSString stringWithFormat:@"%@ has SharedFolders you to a Team Plan.", name] delegate:self cancelButtonTitle:LString(@"CANCEL") otherButtonTitles:[NSMutableArray arrayWithObjects:LString(@"Upgrade Now"),nil]];
alert1.tag = 12365;
[alert1 show];
double delayInSeconds = 5.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
});
}
答案 0 :(得分:3)
您可以使用以下代码解雇UIAlertView。
UIWindow *window = [UIApplication sharedApplication].keyWindow;
for (UIView *view in w.subviews) {
if ([view isKindOfClass:[UIAlertView class]]) {
[(UIAlertView *)view dismissWithClickedButtonIndex:[(UIAlertView *)view cancelButtonIndex] animated:YES];
}
}
我希望,它会对你有帮助。
答案 1 :(得分:0)
UIAlertView *alert = [[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];
}
答案 2 :(得分:0)
UIWindow *Mywindow = [UIApplication sharedApplication].keyWindow;
for (UIView *costumview in w.subviews)
{
if ([view isKindOfClass:[UIAlertView class]])
{
[(UIAlertView *)view dismissWithClickedButtonIndex:[(UIAlertView *)view cancelButtonIndex] animated:YES];
}
}