I am using UIActionSheet to present two options to the user in an iPad app. The user selects one or other option and the UIActionSheetDelegate handles the rest. However, if the user accidentally taps anywhere else on the iPad screen, the UIActionSheet is automatically dismissed and neither of the two options is selected. How can I prevent the UIActionSheet from automatically dismissing, so the user is forced to select one of the two options?
If the Action Sheet is inside a UIPopover, the workaround is to use UIPopoverDelegate to stop the popover from dismissing if the action sheet is present. Another solution would be to use a UIAlertView instead, which will not allow anything to happen except for interacting with the alert. May not be the solution for you. I'm not aware of any other way that a UIActionSheet will just dismiss itself if you touch a different part of the screen.
Create a BOOL variable for when the action sheet is visible
BOOL actionSheetVisible; //in header file
//in @implementation file
-(void)displayAlert {
actionSheetVisible = YES;
//code to display UIAction sheet...
}
#pragma mark PopoverControllerDelegate method
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popover {
if (actionSheetVisible) {
return NO;
}
return YES;
}
#pragma mark UIAlerViewDelegate
...actionSheet:(UIActionSheet *)sheet selectedObjectAtIndex:(NSUInteger)index { ... //not sure what this method is at the moment
actionSheetVisible = NO;
//handle action sheet
}