What is the difference between textFieldShouldendEditing and textfieldDidEndEditing, and when should each method be used?
on textFieldShouldendEditing
:
you should return BOOL
value
YES will resign responsder and NO will stay where it is
textfieldDidEndEditing
will be fired when text field is after edit mode.
as per Apple
This method is called when the text field is asked to resign the first responder status.
This method is called after the text field resigns its first responder status.
textFieldShouldEndEditing:
Asks the delegate if editing should stop in the specified text field.
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
Discussion This method is called when the text field is asked to resign the first responder status. This might occur when your application asks the text field to resign focus or when the user tries to change the editing focus to another control. Before the focus actually changes, however, the text field calls this method to give your delegate a chance to decide whether it should.
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. By returning NO, you could prevent the user from switching to another control until the text field contained a valid value.
textFieldDidEndEditing:
Tells the delegate that editing stopped for the specified text field.
- (void)textFieldDidEndEditing:(UITextField *)textField
Discussion This method is called after the text field resigns its first responder status. You can use this method to update your delegate’s state information. For example, you might use this method to hide overlay views that should be visible only while editing. Implementation of this method by the delegate is optional.
site:apple.com textFieldShouldendEditing
textFieldShouldEndEditing
textFieldDidEndEditing