To programatically hide the keyboard you must call the method resignFirstResponder on your text field or text view. This can be called from anywhere however it is most commonly from a done button or from the keyboard return key being pressed.
[textField resignFirstResponder];
To hide the keyboard when the return key is pressed you must add a listener to the text field (UITextField) delegate method. UITextfieldDelegate protocol contains a method called textFieldShouldReturn, This method is called to determine if the text field should process the pressing of the return key. You can call your resignFirstResponder on the text field from within this method to hide the keyboard when pressed.
- (BOOL)textFieldShouldReturn:(UITextField*)textField {
[textFieldresignFirstResponder];
}
If this doesn't appear to be working for you make sure you've remembered to set the delegate property on the textField.
If you have any problems feel free to post in the comment's ;)