How to dismiss all the alertview from an array when select the cancel button in alertview?

382 views Asked by At

How to dismiss all the alertview from an array when select the cancel button in alertview? I have 5 alertview in an array.. if i choose cancel from the first alertview then it will need to close remaining all alert instead of display.

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

There are 3 answers

2
Anuj J On

You can dismiss UIAlertView using below code.

UIWindow *window = [UIApplication sharedApplication].keyWindow;
for (UIView *view in w.subviews) {
    if ([view isKindOfClass:[UIAlertView class]]) {
        [(UIAlertView *)view dismissWithClickedButtonIndex:[(UIAlertView *)view cancelButtonIndex] animated:YES];
    }
}

I hope, it will help you.

0
Abhinandan Pratap On
 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];

add dismiss method

   -(void)dismiss:(UIAlertView*)alert
    {
        [alert dismissWithClickedButtonIndex:0 animated:YES];
    }
0
Baraiya Bhadresh On
UIWindow *Mywindow = [UIApplication sharedApplication].keyWindow;

for (UIView *costumview in w.subviews) 
{
    if ([view isKindOfClass:[UIAlertView class]])
    {
        [(UIAlertView *)view dismissWithClickedButtonIndex:[(UIAlertView *)view cancelButtonIndex] animated:YES];
    }
}