How to hide Textbox Keyboard when "Done / Return" Button is pressed Xcode 4.2

Talon picture Talon · Jun 10, 2012 · Viewed 80k times · Source

I created a Text Field in Interface Builder. I set it's "Return Key" to Done. This is a one line only input (so it wont need multiple lines).

How do I hide the virtual keyboard when the user taps the done button?

Answer

Paul Hunter picture Paul Hunter · Jun 10, 2012

Implement the delegate method UITextFieldDelegate, then:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.yourIBtextField.delegate = self;
}

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