A set of optional methods that you use to manage the editing and validation of text in a text field object.
- iOS 2.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
A text field calls the methods of its delegate in response to important changes. You use these methods to validate text that was typed by the user, to respond to specific interactions with the keyboard, and to control the overall editing process. Editing begins shortly before the text field becomes the first responder and displays the keyboard (or its assigned input view). The flow of the editing process is as follows:
Before becoming the first responder, the text field calls its delegate’s
textmethod. Use that method to allow or prevent the editing of the text field’s contents.
Field Should Begin Editing(_:)
The text field becomes the first responder.
In response, the system displays the keyboard (or the text field’s input view) and posts the
Will Show Notification
keyboardnotifications as needed. If the keyboard or another input view was already visible, the system posts the
Did Show Notification
Will Change Frame Notification
Did Change Frame Notification
The text field calls various delegate methods during editing:
Whenever the current text changes, it calls the
textmethod and posts the
Field(_: should Change Characters In: replacement String:)
Did Change Notification
It calls the
textmethod when the user taps the built-in button to clear the text.
Field Should Clear(_:)
It calls the
textmethod when the user taps the keyboard’s return button.
Field Should Return(_:)
Before resigning as first responder, the text field calls its delegate’s
textmethod. Use that method to validate the current text.
Field Should End Editing(_:)
The text field resigns as first responder.
For more information about the features of a text field, see