1

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){
        });
    }
Hasya
  • 9,792
  • 4
  • 31
  • 46
Purushothaman
  • 106
  • 1
  • 1
  • 6

3 Answers3

3

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.

Anuj J
  • 186
  • 1
  • 11
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];

add dismiss method

   -(void)dismiss:(UIAlertView*)alert
    {
        [alert dismissWithClickedButtonIndex:0 animated:YES];
    }
Abhinandan Pratap
  • 2,142
  • 1
  • 18
  • 39
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];
    }
}
Pang
  • 9,564
  • 146
  • 81
  • 122