iosiphonecocoa-touchuitextfielduikeyboard

How do you dismiss the keyboard when editing a UITextField


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?


Solution

  • 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;
    }