Instance Method

textFieldShouldReturn(_:)

Asks the delegate if the text field should process the pressing of the return button.

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

func textFieldShouldClear(UITextField) -> Bool

Asks the delegate if the text field’s current contents should be removed.