Difference between textfieldshouldending and textfieldDidenditing in iPhone

What is the difference between textFieldShouldendEditing and textfieldDidEndEditing and when should each method be used?

+6
source share
2 answers

textFieldShouldEndEditing

Request the delegate if editing should stop in the specified text box.

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField 

Discussion This method is called when the text field is prompted to write off the first responder status. This can happen when your application asks for a text field to cancel focus or when a user tries to change the editing to focus on another control. However, before the focus really changes, the text box calls this method to give your delegate the opportunity to decide whether to do so.

Usually you return YES from this method to allow text to remove the status of the first responder. You can return NO, however, in cases where your delegate finds invalid content in the text box. By returning NO, you can prevent the user from switching to another control until the text field contains a valid value.

textFieldDidEndEditing

Informs the delegate that editing is stopped for the specified text field.

 - (void)textFieldDidEndEditing:(UITextField *)textField 

Discussion This method is called after the text field leaves its status as the first responder. This method can be used to update delegate status information. For example, you can use this method to hide overlay views that should only be visible during editing. Implementation of this method by the delegate is optional.

Website: apple.com textFieldShouldendEditing

textFieldShouldEndEditing

textFieldDidEndEditing

+12
source

on textFieldShouldendEditing : you must return the value BOOL YES will cancel the responder, and NO will remain where it is.

textfieldDidEndEditing will be triggered when the text field is after edit mode.

according to Apple

This method is called when the text field is prompted to leave the status of the first responder.

This method is called after the text field has humbled its status as the first responder.

+2
source

Source: https://habr.com/ru/post/924531/


All Articles