0

I'm working on a small project and using several textField.

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
if(textField.tag ==0){
    [self.PWText becomeFirstResponder];
    return false;
}else if(textField.tag ==1){
    [self.PWTextCheck becomeFirstResponder];
    return false;
}else if(textField.tag ==2){
    [self.nameText becomeFirstResponder];
    return false;
}else if(textField.tag ==3){
    [self.phoneText becomeFirstResponder];
    return false;
}else{
    [self.phoneText resignFirstResponder];
    return true;
}}

as I know I'll use this delegate method when I want to make the keyboard disappear when the user tap the "return" button on the keyboard.

no matter which one I returned there no difference as I seen from the simulator, if I want to make the keyboard disappear I use :

[... resignFirstResponder];

and when I want the keyboard focus on one of the textField I use:

[... becomeFirstResponder];

but why should I return a True/False in this method?

Don Chen
  • 7
  • 3

1 Answers1

0

As the documentation states:

The text field calls this method whenever the user taps the return button. You can use this method to implement any custom behavior when the button is tapped.

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITextFieldDelegate_Protocol/index.html#//apple_ref/occ/intfm/UITextFieldDelegate/textFieldShouldReturn

So, if you want to do some sort of action when the user presses the return button, you can implement it here. This way you can perform the action without dismissing the keyboard for that textfield.

Wim Haanstra
  • 5,918
  • 5
  • 41
  • 57
  • I saw an answer from the page Tore Olsean offered, and one of the answer said, if I want to use my own method I should return "false" ,if I returned YES, the delegate would use the default method~ and thank you for your answer :D – Don Chen Feb 09 '15 at 12:13