Take the 2-minute tour ×

I am implementing an action sheet. When I press "ok" button, do these, press "cancel" go back. The "ok" button is working fine, but when I press the "cancel" button, nothing happens, it doesn't retract or do anything, just hang at the actionsheet view.

Below is my code:

To create button on the nav bar:

UIBarButtonItem *clearButton = [[[UIBarButtonItem alloc] initWithTitle:@"Clear     History"
                                                              action:@selector(ClearHistoryAction:)] autorelease];
self.navigationItem.leftBarButtonItem = clearButton;

When I click and launch action sheet:

   - (IBAction)ClearHistoryAction:(id)sender
UIActionSheet *actionSheet = [[UIActionSheet alloc]
                              initWithTitle:@"Clear History?"

// use the same style as the nav bar
actionSheet.actionSheetStyle = self.navigationController.navigationBar.barStyle;    

[actionSheet showInView:self.view];
    [actionSheet release];


if select ok do this:

  - (void)actionSheet:(UIActionSheet *)actionSheet

 didDismissWithButtonIndex:(NSInteger) buttonIndex
if (!buttonIndex == [actionSheet cancelButtonIndex])

    //do what i want here!

In the header file, UIActionSheetDelegate is included in @interface.

share|improve this question
add comment

3 Answers

I don't know if it'll solve this problem but you'll want to do buttonIndex != [actionSheet cancelButtonIndex] (check not-equal) instead of !buttonIndex == [actionSheet cancelButtonIndex] (invert buttonIndex (!) and check if that's equal).

share|improve this answer
add comment

You need to use showFromBarButtonItem instead of showInView. The problem is that the cancel button is being covered by another view--maybe a toolbar or tabbar--so it's not getting the touch events you think it should get. There are also showFromTabBar and showFromToolbar that should sometimes be used (see the UIActionSheet class reference).

share|improve this answer
add comment

Late but, a possible Explanation could be :

Seems to be an issue with the tabbar. If you call UIActionSheet's

[sheet showInView:self.view]

from a view controller that is a child of a UITabViewController, then the hit testing on the cancel button fails in that portion of the UIActionSheet that lies above the tabbar's view.

If you instead pass in the UITabBarController's view, then the UIActionSheet acts as expected.

[sheet showInView:self.parentViewController.tabBarController.view];

A more detailed explanation here: UIActionSheet cancel button strange behaviour

share|improve this answer
add comment

Your Answer


