textFieldShouldReturn is called only if the user presses the return key. If the keyboard is rejected for any other reason, such as a user selecting a different field or switching views to another screen, this will not be the way textFieldDidEndEditing will be.
A better approach is to use textFieldShouldReturn to reject the responder (hide the keyboard) as follows:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
When the keyboard closes, textFieldDidEndEditing is called. Then you can use textFieldDidEndEditing to do something with the text:
- (BOOL)textFieldDidEndEditing:(UITextField *)textField {
But if you really want to perform the action only when the user explicitly presses the "go" or "send" or "search" (or something else) button on the keyboard, then you should put this handler in the textFieldShouldReturn method, like this:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
source share