1

I added a text field, and when I tap in there, the keyboard slides up. What are the steps needed that the keyboard shows an "OK" which actually really works? I mean...hitting "OK" or "Return" does exactly nothing.

Is there some sort of KeyboardDelegateProtocol where I must do some weird stuff like

-(BOOL)shouldReallyGoAway {
    return YES;//of course!
}

Is there an 200 pages keyboard programming guide to read? Couldn't find one...

swiftBoy
  • 33,793
  • 26
  • 129
  • 124
dontWatchMyProfile
  • 42,456
  • 49
  • 169
  • 255
  • 1
    possible duplicate of [How do you dismiss the keyboard when editing a UITextField](http://stackoverflow.com/questions/274319/how-do-you-dismiss-the-keyboard-when-editing-a-uitextfield) – Brad Larson Jun 19 '10 at 12:14
  • 1
    See also http://stackoverflow.com/questions/741185/easy-way-to-dismiss-keyboard – Brad Larson Jun 19 '10 at 12:15

2 Answers2

5

You need to handle the tap on the 'OK' button (Did End On Exit event) and resign the first responder status for the text field.

- (IBAction)textFieldDoneEditing:(id)sender {
[sender resignFirstResponder];

}

You might want to handle few other actions - like the background tap. You'll need an invisible button that will cover your background and trap the taps and an IBOutlet for your text field (since your sender will be the button, not the text field)

BojanG
  • 1,722
  • 1
  • 13
  • 21
2

No reason for a 200 pages guide, it's right there in the introduction of the UITextField which you propably use.

Use

[aTextField resignFirstResponder];

to make the keyboard go away programmatically.

Also, there is the UITextFieldDelegate with appropriate methods regarding Return, which you might use, i.e. -textFieldShouldReturn:.

e.g.

- (BOOL) textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}
foobar
  • 103
  • 2
  • 7
Eiko
  • 25,336
  • 14
  • 53
  • 69