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

# addButton(withTitle:)

Adds a button to the receiver with the given title.

```
func addButton(withTitle title: String?) -> Int
```

## Parameters

`title`

The title of the new button.

## Return Value

The index of the new button. Button indices start at `0` and increase in the order they are added.

## Discussion

Adding too many buttons can cause the alert view to scroll. For guidelines on the best ways to use an alert in an app, see [Temporary Views](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/MobileHIG/Alerts.html#//apple_ref/doc/uid/TP40006556-CH14).

## See Also

[`message`](/documentation/UIKit/UIAlertView/message)

Descriptive text that provides more details than the title.



---

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)