Check if a UIAlertView is showing

后端 未结 10 1348
刺人心
刺人心 2020-11-27 16:45

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.

10条回答
  •  情深已故
    2020-11-27 17:20

    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.

提交回复
热议问题