<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIAlertViewDelegate",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UIAlertViewDelegate"
  },
  "title" : "UIAlertViewDelegate"
}
-->

# UIAlertViewDelegate

The interface for the delegate of an alert view object.

```
@MainActor protocol UIAlertViewDelegate : NSObjectProtocol
```

## Overview

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 alert view, implement a delegate conforming to this protocol to handle the corresponding delegate messages. Use the [`delegate`](/documentation/UIKit/UIAlertView/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:)`](/documentation/UIKit/UIAlertViewDelegate/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:)`](/documentation/UIKit/UIAlertViewDelegate/alertView(_:clickedButtonAt:)) delegate method is invoked.

Optionally, you can implement the [`alertViewCancel(_:)`](/documentation/UIKit/UIAlertViewDelegate/alertViewCancel(_:)) method to take the appropriate action when the system cancels your alert view. If the delegate doesn’t 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.

## Topics

### Responding to actions

[`-  alertView:clickedButtonAtIndex:`](/documentation/UIKit/UIAlertViewDelegate/alertView(_:clickedButtonAt:))

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

### Customizing behavior

[`-  alertViewShouldEnableFirstOtherButton:`](/documentation/UIKit/UIAlertViewDelegate/alertViewShouldEnableFirstOtherButton(_:))

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

[`-  willPresentAlertView:`](/documentation/UIKit/UIAlertViewDelegate/willPresent(_:))

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

[`-  didPresentAlertView:`](/documentation/UIKit/UIAlertViewDelegate/didPresent(_:))

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

[`-  alertView:willDismissWithButtonIndex:`](/documentation/UIKit/UIAlertViewDelegate/alertView(_:willDismissWithButtonIndex:))

Sent to the delegate before an alert view is dismissed.

[`-  alertView:didDismissWithButtonIndex:`](/documentation/UIKit/UIAlertViewDelegate/alertView(_:didDismissWithButtonIndex:))

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

### Canceling

[`-  alertViewCancel:`](/documentation/UIKit/UIAlertViewDelegate/alertViewCancel(_:))

Sent to the delegate before an alert view is canceled.

## Relationships

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)