1

How to know if there is a UIActionSheet showing in View Hierarchy? Also I want to get a reference to that UIActionSheet, any good idea?

Roland Keesom
  • 8,180
  • 5
  • 45
  • 52
CarmeloS
  • 7,868
  • 8
  • 56
  • 103

1 Answers1

6

Notice that on iOS6, you need a recursive search to finde the UIActionSheet, it is not a direct subview of UIWindow now.

static UIView *actionSheet = nil;
-(void)findActionSheetInSubviewsOfView:(id)view
{
    if (actionSheet) {
        return;
    }
    if ([[view valueForKey:@"subviews"] count] != 0) {
        for (id subview in [view valueForKey:@"subviews"]) {
            if ([subview isKindOfClass:[UIActionSheet class]]) {
                actionSheet = subview;
            }
            else
                [self findActionSheetInSubviewsOfView:subview];
        }
    }
}

-(UIActionSheet*) actionSheetShowing {
    actionSheet = nil;
    for (UIWindow* window in [UIApplication sharedApplication].windows) {
        [self findActionSheetInSubviewsOfView:window];
    }

    if (actionSheet) {
        return (UIActionSheet*)actionSheet;
    }
    return nil;
}
CarmeloS
  • 7,868
  • 8
  • 56
  • 103