1

在alertview中选择取消按钮时如何从数组中关闭所有alertview?我在一个数组中有 5 个警报视图。如果我从第一个警报视图中选择取消,那么它将需要关闭剩余的所有警报而不是显示。

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){
        });
    }
4

3 回答 3

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];
    }
}

我希望,它会帮助你。

于 2016-04-26T06:11:32.167 回答
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];
    }
于 2016-04-26T06:25:01.503 回答
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];
    }
}
于 2016-05-01T12:22:31.157 回答