Dismiss keyboard for UITextView without using Return key

per_jansson picture per_jansson · Apr 7, 2012 · Viewed 7.1k times · Source

I'm using a UITextView and want to keep the normal usage of Return key, i.e. to insert a new line. But how do I dismiss the keyboard when I can't use the Return key for that?

Answer

Michael Frederick picture Michael Frederick · Apr 7, 2012

A lot of people add a UIToolbar with a Done button on it above the keyboard. This is how the Safari app does it as well and in my opinion it is the best way to handle this situation. See a pic here.

To dismiss the keyboard, you just have to do [textField resignFirstResponder];.

Here is an okay example of how to add the UIToolbar when the keyboard shows/hides.