Check if a UIAlertView is showing

Ricibald picture Ricibald · Mar 27, 2010 · Viewed 49.5k times · Source

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

Koen picture Koen · Apr 19, 2012

Why not just check the visible property, maintained by the UIAlertView class?

if (_alert) //alert is a retained property
{
    self.alert = [[[UIAlertView alloc] initWithTitle:@"Your Title"
                                             message:@"Your message" 
                                            delegate:self
                                   cancelButtonTitle:@"Cancel"
                                   otherButtonTitles:@"OK"] autorelease];
}
if (!_alert.visible)
{
    [_alert show];
}