0

Possible Duplicate:
How do you dismiss the keyboard when editing a UITextField

I know that I need 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?

Community
  • 1
  • 1

4 Answers4

2

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 {
EmptyStack
  • 51,274
  • 23
  • 147
  • 178
  • Make sure you set your viewcontroller (or whatever is retaining on your text field) as the delegate of the text field, or you won't receive this message. – kevboh Oct 03 '11 at 13:21
1

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..

Vijay
  • 997
  • 1
  • 12
  • 27
0

You can set a delegate on your UITextField : UITextFieldDelegate

Then this method is there for you :

- (BOOL)textFieldShouldReturn:(UITextField *)textField
Jaffa
  • 12,442
  • 4
  • 49
  • 101
0

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;
Nekto
  • 17,837
  • 1
  • 55
  • 65