For apps that run in versions of iOS prior to iOS 8, the UIAlertViewDelegate protocol defines the methods a delegate of a UIAlertView object should implement. The delegate implements the button actions and any other custom behavior. Some of the methods defined in this protocol are optional.


protocol UIAlertViewDelegate


UIAlertViewDelegate is deprecated in iOS 8. (Note that UIAlertView is also deprecated.) To create and manage alerts in iOS 8 and later, use UIAlertController.


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

If you add your own buttons to an alert view, the delegate must implement the alertView(_:clickedButtonAt:) message to respond when those buttons are clicked; otherwise, your custom buttons do nothing. The alert view is automatically dismissed after the alertView(_:clickedButtonAt:) delegate method is invoked.

Optionally, you can implement the alertViewCancel(_:) method to take the appropriate action when the system cancels your alert view. 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 alert views using the methods in Customizing Behavior.


Responding to Actions

func alertView(UIAlertView, clickedButtonAt: Int)

Sent to the delegate when the user clicks a button on an alert view.


Customizing Behavior

func alertViewShouldEnableFirstOtherButton(UIAlertView) -> Bool

Sent to the delegate to determine whether the first non-cancel button in the alert should be enabled.

func willPresent(UIAlertView)

Sent to the delegate before a model view is presented to the user.

func didPresent(UIAlertView)

Sent to the delegate after an alert view is presented to the user.

func alertView(UIAlertView, willDismissWithButtonIndex: Int)

Sent to the delegate before an alert view is dismissed.

func alertView(UIAlertView, didDismissWithButtonIndex: Int)

Sent to the delegate after an alert view is dismissed from the screen.



func alertViewCancel(UIAlertView)

Sent to the delegate before an alert view is canceled.



Inherits From

See Also

Deprecated Protocols

protocol UIViewControllerPreviewing

A set of methods that define the interface for configuring a previewing view controller on devices that support 3D Touch.

protocol UIViewControllerPreviewingDelegate

A set of methods used by the delegate to respond, with a preview view controller and a commit view controller, to the user pressing a view object on the screen of a device that supports 3D Touch.

protocol UIAccelerometerDelegate

The UIAccelerometerDelegate protocol defines a single method for receiving acceleration-related data from the system. Implementation of this method is optional, but expected.

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

protocol UIPopoverControllerDelegate

The UIPopoverControllerDelegate protocol defines the methods you can implement for the delegate of a UIPopoverController object. Popover controllers notify their delegate whenever user interactions would cause the dismissal of the popover and, in some cases, give the user a chance to prevent that dismissal.

protocol UISearchDisplayDelegate

Important: UISearchDisplayDelegate is deprecated in iOS 8. (Note that UISearchDisplayController is also deprecated.) To manage the presentation of a search bar and display search results in iOS 8 and later, instead use UISearchControllerDelegate.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software