29

I am trying to show cancel button in UIActionSheet but it's not showing, is that an acceptable behavior? please advice.

UIActionSheet *actionSheet = [[UIActionSheet alloc]
          initWithTitle:@"Are you sure you want to clear the cache?"
          delegate:self
          cancelButtonTitle:@"No"
          destructiveButtonTitle:@"Yes"
          otherButtonTitles:nil];

[actionSheet showInView:self.view];  

[actionSheet release];

Community
  • 1
  • 1
Ahmad Kayyali
  • 8,236
  • 13
  • 47
  • 83

1 Answers1

56

iPads have some special rules about action sheets and their cancel buttons, depending on where you are displaying it from:

You can present an action sheet from a toolbar, tab bar, button bar item, or from a view. This class takes the starting view and current platform into account when determining how to present the action sheet. For applications running on iPhone and iPod touch devices, the action sheet typically slides up from the bottom of the window that owns the view. For applications running on iPad devices, the action sheet is typically displayed in a popover that is anchored to the starting view in an appropriate way. Taps outside of the popover automatically dismiss the action sheet, as do taps within any custom buttons. You can also dismiss it programmatically.

When presenting an action sheet on an iPad, there are times when you should not include a cancel button. If you are presenting just the action sheet, the system displays the action sheet inside a popover without using an animation. Because taps outside the popover dismiss the action sheet without selecting an item, this results in a default way to cancel the sheet. Including a cancel button would therefore only cause confusion. However, if you have an existing popover and are displaying an action sheet on top of other content using an animation, a cancel button is still appropriate. For more information see iPad Human Interface Guidelines.

Here's a link with more explanation: http://crazyviraj.blogspot.com/2010/05/showing-cancel-button-in.html

nevan king
  • 108,735
  • 42
  • 196
  • 237
  • I am happy reading that, this means I am not making the user confused and looking for the cancel button? – Ahmad Kayyali May 17 '11 at 09:49
  • 5
    Yes, it means that most of the time people just tap somewhere other than the action sheet on iPad to say "cancel". Check the iPad mail app for one way Apple deals with this (in portrait mode, the move button), or in the Photos app for the delete button. – nevan king May 17 '11 at 09:58
  • 1
    In a context on iPad where the Cancel button is not displayed, on iOS8, no "Cancel" string is needed in the UIActionSheet. However, on iOS7 (and earlier?), the "Cancel" string is needed so that you *do* get a separator between the last two items (I think it only applies when you have more than two items). Ugh! – Chris Prince Nov 14 '14 at 22:01
  • @nevanking king Apple create some baffling UI decisions, sometimes. I mean you could apply this logic to an iPhone, and expect the user to press somewhere outside the action sheet, in order to cancel it. I cannot see why an iPad does not include a 'cancel' button. This is not confusing, in any way. In fact, it makes things much clearer...By the way, I am not shooting the messenger, here, so thank you for presenting Apple's comical explanation. – Charles Robertson Nov 06 '16 at 18:13