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?
Asked
Active
Viewed 1,961 times
1

Roland Keesom
- 8,180
- 5
- 45
- 52

CarmeloS
- 7,868
- 8
- 56
- 103
-
use tags for actionsheets and implement the delegates. – Pranjal Bikash Das Jan 15 '13 at 10:36
-
1possible duplicate: http://stackoverflow.com/questions/4363317/iphone-detecting-if-a-uialert-uiactionsheet-are-open, take a look at the second answer – Hvordan har du det Jan 15 '13 at 10:39
-
@RoxDorentus I don't think its a total duplicate, but it do solved my problem, thank you. – CarmeloS Jan 15 '13 at 10:56
1 Answers
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