<!--
{
  "availability" : [
    "iOS: 2.0.0 - 9.0.0",
    "iPadOS: 2.0.0 - 9.0.0",
    "macCatalyst: 13.1.0 - 13.1.0"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIAlertViewDelegate/alertViewCancel(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UIAlertViewDelegate(im)alertViewCancel:"
  },
  "title" : "alertViewCancel(_:)"
}
-->

# alertViewCancel(_:)

Sent to the delegate before an alert view is canceled.

```
optional func alertViewCancel(_ alertView: UIAlertView)
```

## Parameters

`alertView`

The alert view that will be canceled.

## Discussion

If the alert view’s delegate does not implement this method, clicking the cancel button is simulated and the alert view is dismissed. Implement this method if you need to perform some actions before an alert view is canceled. An alert view can be canceled at any time by the system—for example, when the user taps the Home button. The [`alertView(_:willDismissWithButtonIndex:)`](/documentation/UIKit/UIAlertViewDelegate/alertView(_:willDismissWithButtonIndex:)) and [`alertView(_:didDismissWithButtonIndex:)`](/documentation/UIKit/UIAlertViewDelegate/alertView(_:didDismissWithButtonIndex:)) methods are invoked after this method.

---

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)