views:

186

answers:

2

I made a text field but I didn't use Interface Builder, I did it programatically in XCode. So now I need a programmatic way to make it resign first responder so that the keyboard will go away when the user presses enter.

+1  A: 
[textField resignFirstResponder];

docs

if you want it to go away when enter is pressed, you will need to implement

- (BOOL)textFieldShouldReturn:(UITextField *)textField

in your UITextFieldDelegate

cobbal
+1  A: 

As addition to cobbal's answer, don't forget to set text field's delegate to the class that implements

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

Adding descriptor to that class interface declaration is also a good thing.

NR4TR