How do you dismiss the keyboard when editing a UITextField

kubi picture kubi · Nov 8, 2008 · Viewed 193.1k times · Source

I know that I need to tell my UITextField to resign first responder when I want to dismis the keyboard, but I'm not sure how to know when the user has pressed the "Done" key on the keyboard. Is there a notification I can watch for?

Answer

kubi picture kubi · Nov 8, 2008

I set the delegate of the UITextField to my ViewController class.

In that class I implemented this method as following:

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