Search code examples
iphoneiosobjective-cuialertviewios6.1

alertView didDismissWithButtonIndex never called


Please excuse me if something is not post right... first time posting.

I have seen a few questions simular to this but none with the same problem. I am running IOS 6.1 and Xcode 4.6. The problem is that didDismiss is never called, only willDismiss. My code is below along with the log output. Any ideas?

#import "MenkLabUIAlertTestViewController.h"

@interface MenkLabUIAlertTestViewController ()

@end

@implementation MenkLabUIAlertTestViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.


}
- (IBAction)test:(id)sender {
    UIAlertView *av  = [[UIAlertView alloc] initWithTitle:@"Encrypting File(s)" message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
    //    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [av show];
    [av dismissWithClickedButtonIndex:-1 animated:YES];
}

- (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"willDISMIS");
}

- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"didDISMIS");
   }


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

Log output:

2013-07-08 17:27:04.055 testUIAlertView[10534:11303] willDISMIS

This is just a test app, however, it is the exact same problem that exists in my current application.

Thanks in advanced. Been racking my head on this all day!


Solution

  • I think this an artifact of the fact that you are showing, then immediately dismissing the alert view in the same method -- you would never actually do this in a real app. If you create a property for the alert view, and then do the test like below, it works fine:

    - (IBAction)test:(id)sender {
        self.av  = [[UIAlertView alloc] initWithTitle:@"Encrypting File(s)" message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        [self.av show];
        [self performSelector:@selector(dismissAlertView) withObject:nil afterDelay:1];
    }
    
    
    -(void)dismissAlertView {
        [self.av dismissWithClickedButtonIndex:-1 animated:YES];
    }
    
    - (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
        NSLog(@"willDISMIS");
    }
    
    - (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
        NSLog(@"didDISMIS");
    }