Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using UIActionSheet on iPad

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!

like image 782
GendoIkari Avatar asked Nov 02 '10 14:11

GendoIkari


People also ask

How do I show Actionsheet on IPAD Swift?

You must provide either a sourceView and sourceRect or a barButtonItem . If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation .

What is action sheet in iOS?

An action sheet is a modal view that presents choices related to an action people initiate. DEVELOPER NOTE When you use SwiftUI, you can enable action sheet functionality in all platforms by specifying a presentation modifier for a confirmation dialog.

Which class is used to show an Actionsheet in iOS?

Overview. In apps that target versions of iOS prior to iOS 8, use the UIActionSheet class to present the user with a set of alternatives for how to proceed with a given task. You can also use action sheets to prompt the user to confirm a potentially dangerous action.

What is action sheet in iOS Swift?

An action sheet is a specific style of alert that appears in response to a control or action, and presents a set of two or more choices related to the current context.


1 Answers

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.

like image 133
omz Avatar answered Oct 20 '22 00:10

omz