I have view with a text field, an image and a few buttons. I want to make sure the keyboard is displayed and is on top when the view is displayed AND I want to make sure it doesn't go away after I type something in to the text field and submit it.
I called [txtField becomeFirstResponder]
with viewdidload and the keyboard is appearing by default but with a tiny delay after the view is displayed.
Also the becomefirstresponder doesn't help after I have my text field submitted.
Thanks in advance for your help!
Also the becomefirstresponder doesn't help after I have my text field submitted.
That part makes no sense. By default, a text field does not dismiss the keyboard unless you dismiss it with endEditing:
or resignFirstResponder
. If the keyboard is going away, you must be making it go away. So don't and it won't.
EDIT: And indeed, your comment later reveals the answer: you've hooked up the didEndOnExit
control event from the text field. Well, that causes the keyboard to be dismissed when the user presses the Done button! So you are effectively hitting yourself in the face and then complaining that someone is hitting you in the face.
So the solution, obviously, is don't hook up the didEndOnExit
control event (to anything). Instead, just give the text field a delegate and use the delegate messages to learn what the user is doing. None of those have any automatic behavior with regard to the keyboard, so the keyboard won't be dismissed automatically. For example, to learn when the user is typing, use textField:shouldChangeCharactersInRange:replacementString:
. To learn when the user has hit the Done button, use textFieldShouldReturn:
. And so on.
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