Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if UIView is displaying a UIAlertView

Is it possible to determine if the current UIView has a UIAlertView on display (other than setting a variable every time a UIAlertView is created).

I'm thinking something along the lines of

    if ([self.view.subviews containsObject:UIAlertView]) { ... }

But that obviously doesn't work.

like image 656
Smikey Avatar asked Nov 28 '22 17:11

Smikey


2 Answers

This will not work in iOS7 and above.

[alertView Show] adds subview on main window I guess.

for (UIWindow* window in [UIApplication sharedApplication].windows){
    for (UIView *subView in [window subviews]){
        if ([subView isKindOfClass:[UIAlertView class]]) {
            NSLog(@"has AlertView");
        }else {
            NSLog(@"No AlertView");
        }
    }
}

like image 61
Warif Akhand Rishi Avatar answered Dec 09 '22 15:12

Warif Akhand Rishi


I think it will work:

-(BOOL) doesAlertViewExist 
{
    if ([[UIApplication sharedApplication].keyWindow isMemberOfClass:[UIWindow class]])
    {
        return NO;//AlertView does not exist on current window
    }
    return YES;//AlertView exist on current window
}
like image 36
Kyle C Avatar answered Dec 09 '22 17:12

Kyle C