开发者

How to make the keyboard go away?

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开发者_C百科't find one...


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)


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜