Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between textfieldshouldendediting and textfieldDidendediting in iPhone

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

like image 924
Ben10 Avatar asked Sep 04 '12 11:09

Ben10


1 Answers

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

like image 82
janusfidel Avatar answered Oct 09 '22 22:10

janusfidel