When i press the done button on the keyboard, it automatically puts the keyboard away. How do i stop it from doing this?
-
1I thought it doesn't do that by default. Do you have a delegate method to respond to the done button? – BoltClock Jan 12 '11 at 02:14
-
1Hmm...this isn't how it should be. To even get the behavior you are describing, you have to call `resignFirstResponder` in your `textFieldShouldReturn` method in your text field delegate. If you want this to stop, find that delegate method and don't call resignFirstResponder. – Alex Jan 12 '11 at 02:15
3 Answers
Make sure that your view controller is set as the UITextField
's delegate, then implement the shouldEndEditing: method. Just return NO
to keep the text field active and keep the keyboard on the screen.
Of course, this may not be the best approach but after reading the docs above you should be able to find the right callback and control your program's flow appropriately.

- 4,329
- 8
- 34
- 39
Your controller needs to implement the textFieldShouldReturn:
method of the UITextFieldDelegate
(reference):
Make sure that your view controller has been set as the delegate for your textfield, either through Interface Builder or in code:
- (void) viewDidLoad
{
self.someTextField.delegate = self;
}
Then, in your view controller, you will need to implement the textFieldShouldReturn:
method:
- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
return NO;
}
What you are specifying is that no action should occur when the return (done) key is pressed on the keyboard. What is odd, as others have mentioned, is that this is precisely the default behavior. This means that 1) you are calling the resignFirstResponder
on your text field or, 2) this text field is inside a UIWebView
and good luck changing that behavior.

- 18,369
- 7
- 84
- 116
I had the similar situation. When [myTextField resignResponder] occurred, the keyboard disappeared, but I just wanted to keep the keyboard appearing in the screen.
I just made one extra UITextField instance outside the screen, say dummyTextField, and its frame is CGRectMake(-10,-10,5,5).
And after [myTextField resignResponder], I immediately called [dummyTextField becomeFirstResponder]. So the keyboard is still alive, while the user can't see dummyTextField.
I believe there's a better way to do it. But I did in this way, and it worked fine.

- 1,127
- 1
- 14
- 22