iOS Developer Library

Developer

UIKit Framework Reference UIActionSheetDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIActionSheetDelegate

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.

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 8.3.

  • 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.

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 8.3.