How do I determine if the cancel button was pressed on a UIActionSheet?
My UIActionSheet is set up like this:
-(IBAction)fileButtonPressed
{
UIAction
add this
[mymenu showInView:self.parentViewController.tabBarController.view];
if (buttonIndex == actionSheet.cancelButtonIndex)
{
// Handle cancel action
}
UIActionSheet also has properties like destructiveButtonIndex
and firstOtherButtonIndex
to compare against.
The trick turns out to be not to use the automatic cancel button but to add it yourself.
The other slight gotcha is to add the cancel button at the end and not at the beginning.
-(IBAction)fileButtonPressed
{
UIActionSheet *mymenu = [[UIActionSheet alloc]
initWithTitle:@"Select Folder"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (int nb=0; nb<3; nb++)
{
[mymenu addButtonWithTitle:@"Button Name"];
}
mymenu.cancelButtonIndex = [mymenu addButtonWithTitle: @"Cancel"];
[mymenu showInView:self.view];
}
credit to this stackoverflow entry for the answer.