<!--
{
  "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/UIAlertView/dismiss(withClickedButtonIndex:animated:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIAlertView(im)dismissWithClickedButtonIndex:animated:"
  },
  "title" : "dismiss(withClickedButtonIndex:animated:)"
}
-->

# dismiss(withClickedButtonIndex:animated:)

Dismisses the receiver, optionally with animation.

```
func dismiss(withClickedButtonIndex buttonIndex: Int, animated: Bool)
```

## Parameters

`buttonIndex`

The index of the button that was clicked just before invoking this method. The button indices start at `0`.

`animated`

<doc://com.apple.documentation/documentation/Swift/true> if the receiver should be removed by animating it first; otherwise, <doc://com.apple.documentation/documentation/Swift/false> if it should be removed immediately with no animation.

## Discussion

In iOS 4.0, you may want to call this method whenever your application moves to the background. An alert view is not dismissed automatically when an application moves to the background. This behavior differs from previous versions of the operating system, where they were canceled automatically when the application was terminated. Dismissing the alert view gives your application a chance to save changes or abort the operation and perform any necessary cleanup in case your application is terminated later.

---

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)