meds
meds

Reputation: 22926

Losing focus from text input area in iOS?

I have a text box in a view, when I focus it the keyboard pops up, I can type some stuff in, but when I'm done with it I can't lose focus to it. Like if I click outside the text box the keyboard remains.

How can I get rid of the keyboard?

Upvotes: 2

Views: 3240

Answers (1)

sosborn
sosborn

Reputation: 14694

From the docs:

It is your application’s responsibility to dismiss the keyboard at the time of your choosing. You might dismiss the keyboard in response to a specific user action, such as the user tapping a particular button in your user interface. You might also configure your text field delegate to dismiss the keyboard when the user presses the “return” key on the keyboard itself. To dismiss the keyboard, send the resignFirstResponder message to the text field that is currently the first responder. Doing so causes the text field object to end the current editing session (with the delegate object’s consent) and hide the keyboard.

Here is one way to do it using a UITextFieldDelegate method:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
   [textField resignFirstResponder];
}

Make sure you hook up the delegate to the textField.

Upvotes: 5

Related Questions