views:

154

answers:

3

How to Hide Keyboard by pressing Returnkey

+2  A: 

The keyboard only shows up when something editable (usually a UITextField) has become the first responder. Therefore, to make the keyboard go away, you have to make the textField not be the firstResponder anymore. Fortunately, it's one line of code:

[myTextField resignFirstResponder];
Dave DeLong
+2  A: 

You really need to include more information with your question, but I think this might be what you are looking for:

First, make your view controller implement the UITextFieldDelegate:

@interface MainViewController : UIViewController <UITextFieldDelegate> {

Then add this method to the controller:

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

Read the UITextFieldDelegate documentation to see what else you can do.

Felixyz
+3  A: 
Niels Hansen