<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIAlertController/addTextField(configurationHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIAlertController(im)addTextFieldWithConfigurationHandler:"
  },
  "title" : "addTextField(configurationHandler:)"
}
-->

# addTextField(configurationHandler:)

Adds a text field to an alert.

```
func addTextField(configurationHandler: ((UITextField) -> Void)? = nil)
```

## Parameters

`configurationHandler`

A block for configuring the text field prior to displaying the alert. This block has no return value and takes a single parameter corresponding to the text field object. Use that parameter to change the text field properties.

## Discussion

Calling this method adds an editable text field to the alert. You can call this method more than once to add additional text fields. The text fields are stacked in the resulting alert.

You can add a text field only if the [`preferredStyle`](/documentation/UIKit/UIAlertController/preferredStyle) property is set to [`UIAlertController.Style.alert`](/documentation/UIKit/UIAlertController/Style/alert).

---

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)