开发者

How to dissmiss keybord when editing UITextField [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How do you dismiss the keyboard when editing a UITextField

I know that I ne开发者_运维百科ed to tell my UITextField to resign first responder when I want to dismis the keyboard, but I'm not sure how to know when the user has pressed the "Done" key on the keyboard. Is there a notification I can watch for?


You should implement this method to know if the user has just pressed the return key (that key is called "return key"), and don't forget to return YES from this method.

- (BOOL)textFieldShouldReturn:(UITextField*)textField {


set the delegate of the UITextFieldDelegate ViewController(.h file) class and impliment following method in viewController (.m file) class.

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

It will work..


You can set a delegate on your UITextField : UITextFieldDelegate

Then this method is there for you :

- (BOOL)textFieldShouldReturn:(UITextField *)textField


You should implement next methods in your UITextFieldDelegate class:

Tells the delegate that editing stopped for the specified text field.

- (void)textFieldDidEndEditing:(UITextField *)textField;

Asks the delegate if the text field should process the pressing of the return button.

- (BOOL)textFieldShouldReturn:(UITextField *)textField;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜