iOS Developer Library

Developer

UIKit Framework Reference UIActionSheetDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIActionSheetDelegate

Inheritance


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.

Important: UIActionSheetDelegate is deprecated in iOS 8. (Note that UIActionSheet is also deprecated.) To create and manage action sheets in iOS 8 and later, use UIAlertController.

The UIActionSheetDelegate protocol defines the methods a delegate of a UIActionSheet object should implement. The delegate implements the button actions and any other custom behavior. Some of the methods defined in this protocol are optional.

If you add your own buttons or customize the behavior of an action sheet, implement a delegate conforming to this protocol to handle the corresponding delegate messages. Use the delegate property of the action sheet object to specify one of your application objects as the delegate.

If you add your own buttons to an action sheet, the delegate must implement the actionSheet:clickedButtonAtIndex: message to respond when those buttons are clicked; otherwise, your custom buttons do nothing. The action sheet is automatically dismissed after the actionSheet:clickedButtonAtIndex: delegate method is invoked.

Optionally, you can implement the actionSheetCancel: method to take the appropriate action when the system cancels your action sheet. If the delegate does not implement this method, the default behavior is to simulate the user clicking the cancel button and closing the view.

You can also optionally augment the behavior of presenting and dismissing action sheets using the methods in Customizing Behavior.

  • Sent to the delegate when the user clicks a button on an action sheet.

    Declaration

    Swift

    optional func actionSheet(_ actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int)

    Objective-C

    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

    Parameters

    actionSheet

    The action sheet containing the button.

    buttonIndex

    The position of the clicked button. The button indices start at 0.

    Discussion

    The receiver is automatically dismissed after this method is invoked.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sent to the delegate before an action sheet is presented to the user.

    Declaration

    Swift

    optional func willPresentActionSheet(_ actionSheet: UIActionSheet)

    Objective-C

    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet

    Parameters

    actionSheet

    The action sheet that is about to be displayed.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sent to the delegate after an action sheet is presented to the user.

    Declaration

    Swift

    optional func didPresentActionSheet(_ actionSheet: UIActionSheet)

    Objective-C

    - (void)didPresentActionSheet:(UIActionSheet *)actionSheet

    Parameters

    actionSheet

    The action sheet that was displayed.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sent to the delegate before an action sheet is dismissed.

    Declaration

    Swift

    optional func actionSheet(_ actionSheet: UIActionSheet, willDismissWithButtonIndex buttonIndex: Int)

    Objective-C

    - (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex

    Parameters

    actionSheet

    The action sheet that is about to be dismissed.

    buttonIndex

    The index of the button that was clicked. If this is the cancel button index, the action sheet is canceling. If -1, the cancel button index is not set.

    Discussion

    This method is invoked before the animation begins and the view is hidden.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sent to the delegate after an action sheet is dismissed from the screen.

    Declaration

    Swift

    optional func actionSheet(_ actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int)

    Objective-C

    - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex

    Parameters

    actionSheet

    The action sheet that was dismissed.

    buttonIndex

    The index of the button that was clicked. The button indices start at 0. If this is the cancel button index, the action sheet is canceling. If -1, the cancel button index is not set.

    Discussion

    This method is invoked after the animation ends and the view is hidden.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sent to the delegate before an action sheet is canceled.

    Declaration

    Swift

    optional func actionSheetCancel(_ actionSheet: UIActionSheet)

    Objective-C

    - (void)actionSheetCancel:(UIActionSheet *)actionSheet

    Parameters

    actionSheet

    The action sheet that will be canceled.

    Discussion

    If the action sheet’s delegate does not implement this method, clicking the cancel button is simulated and the action sheet is dismissed. Implement this method if you need to perform some actions before an action sheet is canceled. An action sheet can be canceled at any time by the system—for example, when the user taps the Home button. The actionSheet:willDismissWithButtonIndex: and actionSheet:didDismissWithButtonIndex: methods are invoked after this method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.