UITextField - capture return button event

Ilya Suzdalnitski picture Ilya Suzdalnitski · Jun 10, 2009 · Viewed 67.5k times · Source

How can I detect when a user pressed "return" keyboard button while editing UITextField? I need to do this in order to dismiss keyboard when user pressed the "return" button.

Thanks.

Answer

Ilya Suzdalnitski picture Ilya Suzdalnitski · Jun 10, 2009
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return NO;
}

Don't forget to set the delegate in storyboard...

enter image description here