
How to hide the keyboard when done is pressed on a TextField
After lots of searching I finally found the answer.
When Done (Or Search, Yahoo, etc) is pressed on the popup keyboard on the iPhone, you have to send the textfield a resignFirstResponder message.
To know when done is pressed you need to make your controller the delegate for that textField. To do this, in interface builder, control click the textfield and drag to the controller and select delegate.
Once the controller is the delegate for the textField, you'll be able to implement the UITextFieldDelegate Protocol.
In this protocol is this message in particular:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
As you can see my controller is for multiple text fields and the message is handled by textFieldShouldReturn.
And to quote another source that really made this clear for me, here is an excerpt I found that helped.
[object setDelegate:delegateObject];
The article quoted above is available at Five Approaches to Listening, Observing and Notifying in Cocoa

