textFieldShouldEndEditing(_:)
Asks the delegate whether to stop editing in the specified text field.
Declaration
optional func textFieldShouldEndEditing(_ textField: UITextField) -> BoolParameters
- textField:
The text field in which editing is about to end.
Return Value
Discussion
The text field calls this method when it is asked to resign the first responder status. This can happen when the user selects another control or when you call the text field’s resignFirstResponder() method. Before the focus change occurs, however, the text field calls this method and gives you a chance to prevent the change from happening.
Normally, you would return true from this method to allow the text field to resign the first responder status. You might return false, however, in cases where your delegate detects invalid contents in the text field. Returning false prevents the user from switching to another control until the text field contains a valid value.
Be aware that this method provides only a recommendation about whether editing should end. Even if you return false, UIKit might still force an end to editing. For example, text fields always resign the first responder status when they are removed from their parent view or window.
Implementation of this method by the delegate is optional. If you do not implement this method, the text field resigns the first responder status as if this method had returned true.