Ricibald Ricibald - 1 year ago 90
Objective-C Question

iPhone SDK: check if a UIAlertView is showing

I have a method that posts HTTP data and displays a UIAlertView if there is an error. If I have multiple HTTP post I will show multiple UIAlertView for every error.

I want to show a UIAlertView only if is not showing other UIAlertView.
How can I determine this?

Answer Source

On the object that calls set an ivar before invoking the show method on your UIAlertView.


if (!self.alertShowing) {
    theAlert = [[UIAlertView alloc] initWithTitle:title message:details delegate:self cancelButtonTitle:nil otherButtonTitles:@"Okay", nil];
    self.alertShowing = YES;
    [theAlert show];


Then in your delegate method for the alert manage setting your flag ivar to no:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
      self.alertShowing = NO;

If you want the alerts to show sequentially, I would post notifications to add each message to a queue and then only take a message off the queue after an alert is dismissed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download