0

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!

Menklab
  • 50
  • 1
  • 6

5 Answers5

2

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");
}
rdelmar
  • 103,982
  • 12
  • 207
  • 218
0

I had faced a similar issue, as a workaround we added a selector Method which runs after some delay which will instead trigger the dismissal of alert view. I am not sure why it does not work if we ask the alert to to dismiss immediately after it is shown. Hope it helps.

Anup
  • 42
  • 5
0

I ran into this problem too. For me it was related to trying to programatically dismiss it with a button index on -1. We ended up going down a different path in the end for other reasons. However, There is a cancel button index on the actionsheet that you can try calling it with.

Chip Snyder
  • 418
  • 3
  • 13
0

I ran into this problem once. For me the problem was caused by a collision between animations. The didDismiss selector is called when the animation ends. If another animation is started between willDismiss and didDismiss then in some rare circumstances the didDismiss doesn't have to be called.

Also note that it never works well if you try to dismiss the alert before it is fully displayed.

Sulthan
  • 128,090
  • 22
  • 218
  • 270
0

I have added. That solves my problem.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1)
     {
     }
}
Ram G.
  • 3,045
  • 2
  • 25
  • 31