Do not display a warning if another warning is already displayed on iphone

On iPhone, how can I check if it is still UIAlertViewdisplayed before displaying UIAlertView?

+3
source share
2 answers

I don’t think there is any built-in method for determining if there are any warnings. The way I dealt with this in the past is to keep track of the warnings displayed, displaying them as a property:

UIAlertView *currentAlert;

and when they are fired, install:

currentAlert = nil; 

Then you just check to see if currentAlert == nil before displaying another.

Obviously, there are main disadvantages of this method, including, but not limited to:

  • it only works with the alerts you show, not system alerts.
  • UIAlertViewDelegate
  • currentAlert , viewControllers, , .

, .

+2

:

for( UIView* subview in [UIApplication sharedApplication].keyWindow.subviews ) {
    if( [subview isKindOfClass:[UIAlertView class]] ) {
        NSLog( @"Alert is showing" );
        break;
    }
}

, , Apple .

+5

All Articles