Contents

textFieldShouldReturn(_:)

Asks the delegate whether to process the pressing of the Return button for the text field.

Declaration

optional func textFieldShouldReturn(_ textField: UITextField) -> Bool

Parameters

  • textField:

    The text field whose return button was pressed.

Return Value

true if the text field should implement its default behavior for the return button; otherwise, false.

Discussion

The text field calls this method whenever the user taps the return button. You can use this method to implement any custom behavior when the button is tapped. For example, if you want to dismiss the keyboard when the user taps the return button, your implementation can call the resignFirstResponder() method.

See Also

Editing the text field’s text