Using UIActionSheet on iPad

GendoIkari picture GendoIkari · Nov 2, 2010 · Viewed 25.4k times · Source

Apple's documentation for the UIActionSheet is causing me confusion. First off, in the iPad Human Interface Guidelines, it says :

To learn more about using an action sheet in your code, see “Using Popovers to Display Content” in iPad Programming Guide.

But then in the "Using Popovers to Display Content" section, it doesn't mention Action Sheets at all! Am I missing something here?

http://developer.apple.com/library/ios/#documentation/General/Conceptual/iPadHIG/UIElements/UIElements.html#//apple_ref/doc/uid/TP40009446-CH6-SW9

My main question is this: on the iPad, what is the difference between a UIPopoverController and a UIActionSheet? If a UIActionSheet automatically presents itself inside a UIPopoverController, is there any reason to use UIActionSheet at all? I see how its delegate and automatic creation of buttons makes for fewer lines of code, but from a usability POV, is there a difference?

Also, displaying my actionSheet with animation is not working at all. It looks and acts exactly like an actionSheet presented without animation (which is exactly the same as if I were just using a UIPopoverController and no actionSheet at all). Here's my code:

UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"An unsaved property already exists. You must assign a name to this property before creating a new property. Would you like to:"
    delegate:self
    cancelButtonTitle:nil
    destructiveButtonTitle:@"Overwrite"
    otherButtonTitles:@"Open unsaved property", nil];

[action showFromRect:CGRectMake(0, 0, 200, 200) inView:self.mainSplitViewController.view animated:NO];

How would I get an actionSheet that looks like the sample animated actionSheet in Apple's documentation (from the maps application, where you add a location to a contact)?

I may just end up using an alert for this rather than a popover or an actionSheet, but it would still be useful to understand this.

Thanks!

Answer

omz picture omz · Jan 14, 2011

First of all, UIActionSheet existed before UIPopoverController and UIPopoverController isn't available on iPhone, so it's useful for backwards compatibility and universal apps.

Also, a UIActionSheet isn't necessarily presented in a popover, specifically, if you show it from a UIBarButtonItem or UIToolbar that is already inside a popover. It is then presented in a similar fashion as on the iPhone (sliding in from the bottom of the view controller). According to the HIG, you must not present multiple popovers at the same time (I once had an app rejected for that), so in cases where a view controller may be inside a popover (like in a standard split view app), you may want to use action sheets, if possible. Of course there are a lot of cases where you can't replace a popover with an action sheet, because an action sheet only shows a list of buttons and a title, whereas a popover can display any view controller.

I think that the animated parameter only has an effect when an action sheet is presented in the "classic" (as on iPhone) way.