I am hiding keyboard on return key pressed by implementing function textFieldShouldReturn
and calling resignFirstResponder()
inside this function. It works perfectly but when I return false
in this function, still then keyboard is hiding. Now here I do not understand that what is use of returning true
or false
if keyboard is hiding in both case?
The keyboard is being dismissed due to the call to resignFirstResponder
. It has nothing at all to do with the return value of textFieldShouldReturn
.
In my experience, the return value of textFieldShouldReturn
almost has no use. In the vast majority of cases it makes no difference whether you return true
, or false
.
I return false
in all my uses of testFieldShouldReturn
. If you return true
and your implementation of textFieldShouldReturn
sets the first responder to a UITextView
, the text view ends up getting the newline added to it. Returning false
from textFieldShouldReturn
ensures this won't happen. But this was based on experience with iOS 4 or 5 a few years ago. I don't know if that still happens with the latest versions of iOS.
The return value from textFieldShouldReturn
answers a different question. If the text field has an action for the control event editingDidEndOnExit
, that will cause the keyboard to dismiss unless textFieldShouldReturn
is implemented to return false
.
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