Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically dismissing a UIAlertView on iOS 5 doesn't call didDismiss delegate method

I'm running into a problem where 9 times out of ten, when I call UIAlertView's dismissWithClickedButtonIndex:animated:, the delegate method alertView:willDismissWithButtonIndex: is not called. Is anyone else running into this problem? I'm about to file a bug with Apple but I'm curious to see if anyone else has run into this issue and figured out any workarounds.

like image 238
Vince Avatar asked Dec 17 '22 08:12

Vince


1 Answers

To ensure a consistent behavior across iOS4 and 5, you could just remove the UIAlertView's delegate just prior to calling its dismissWithClickedButtonIndex:animated: method, then manually invoke the delegate method. e.g.

- (void)somethingDidHappen {
    id<UIAlertViewDelegate> delegate = myAlertView.delegate;
    myAlertView.delegate = nil;
    // now, we know the delegate won't be called...
    [myAlertView dismissWithClickedButtonIndex:0 animated:NO];
    // ...so we call it ourselves below
    [delegate alertView:myAlertView clickedButtonAtIndex:0];
}

(That code isn't tested, but you get the point.)

like image 112
Dave Taubler Avatar answered May 14 '23 09:05

Dave Taubler