Instance Method

textFieldShouldEndEditing:

Asks the delegate if editing should stop in the specified text field.

Declaration

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;

Parameters

textField

The text field in which editing is about to end.

Return Value

YES if editing should stop or NO if it should continue.

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 YES from this method to allow the text field to resign the first responder status. You might return NO, however, in cases where your delegate detects invalid contents in the text field. Returning NO 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 NO, 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 YES.

See Also

Managing Editing

- textFieldShouldBeginEditing:

Asks the delegate if editing should begin in the specified text field.

- textFieldDidBeginEditing:

Tells the delegate that editing began in the specified text field.

- textFieldDidEndEditing:reason:

Tells the delegate that editing stopped for the specified text field.

- textFieldDidEndEditing:

Tells the delegate that editing stopped for the specified text field.

UITextFieldDidEndEditingReason

Constants indicating the reason why editing ended in a text field.