Tuesday, November 23, 2010

UIActionSheet Last Button Not Responding

Your UIActionSheet's bottom button, most likely Cancel, is not responsing to tap.

Check whether there is a UITabBar or UIToolbar below it. The problem is that most likely you try to show actionSheet as subview of your current view, which starts only above tabs and toolbar. However since actionSheet is always shown attached to bottom of the screen, you will miss taps outside your view.

The fix is to show your actionSheet in the whole application window, instead of subview of your current view:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
    delegate:self
    cancelButtonTitle:@"Cancel"
    destructiveButtonTitle:nil
    otherButtonTitles:@"Button", nil];
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
[actionSheet release];

3 comments:

  1. Did have this problem long time ago. Thanks for sharing.

    ReplyDelete
  2. I had problem adding UIActionSheet in self.view when the view is in UIScrollView. Tried your solution. It worked great! :-) Thanks a lot!

    ReplyDelete