This is the text field delegate method but i have doubt about return type
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return NO;
}
and this is the same method with different return type
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
by both we can hide key board in i phone . but what is the meaning of return type "YES" or "NO". I am not seeing any difference.
In addition to the other answers here (which essentially confirm there's no major difference, no auto-resigning of the first responder by returning YES
, etc.), I've discovered a strange occurrence completely dependent on the return value, specifically for a UITextField
with autocorrection.
You have a UITextField
with autocorrection enabled
You've implemented the delegate method something like this (where the text field gets resigned):
- (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == self.myAutocorrectingTextField) { [self.myAutocorrectingTextField resignFirstResponder]; } return YES; }
You run the app, type "Cable" into the text field, then press the return key, resigning it as first responder.
YES
:I have tested a handful of other words that respond similarly:
NO
:Normal. The text field's text will not have been changed.
When returning YES
, the text field may autocorrect already-correct words. It does not, however, present one of those "autocorrect text bubbles", because these are legitimate words.
When returning NO
, the text field will not autocorrect already-correct words.
Note: In both cases, incorrectly-spelled words will always be corrected. For example:
One difference that I see based on personal experience is that if you return YES, auto correction and auto capitalization are triggered, if you return NO, they are not. There might be other things done, but that's all I could notice so far.
That's what they mean by "default behavior".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With