-3

I have a button that when pressed brings up a keyboard for a textfield:

- (IBAction)textButtonPress:(id)sender {
    [self.textField becomeFirstResponder];
}

The problem I have is that when I press the return button on the keyboard nothing happens. How can I make the keyboard automatically close when the return key is pressed?

Tyler Hilbert
  • 2,107
  • 7
  • 35
  • 55

1 Answers1

3

Add this in your ViewController class

yourTextField.delegate = self

and this UITextFieldDelegate method

-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}
Rajan Maheshwari
  • 14,465
  • 6
  • 64
  • 98