2

I have tried this solution to hide keyboard but it doesn't work...

How to hide the keyboard when i press return key in a UITextField?

Many thanks

Community
  • 1
  • 1
roof
  • 450
  • 3
  • 13
  • 20

3 Answers3

11

assuming you are using UITextField, how do you create the textfield? is it by xib? or by code? make sure you implement UITextFieldDelegate in your class

@interface YouClass : UIViewController <UITextFieldDelegate>

if its xib, connect your textField to the file owner's delegate. and also connect your File owner to your IBOutlet UITextField

enter image description here

if its by code. just do

yourTextField.delegate = self;

now implement

-(BOOL)textFieldShouldReturn:(UITextField *)textField
janusfidel
  • 8,036
  • 4
  • 30
  • 53
0

Just resign as first responder in your input text field, when the return key pressed. The keyboard will dismissed automatically.

Nevin
  • 7,689
  • 1
  • 23
  • 25
0

You need to set the Return button to actual built in function type. In one of my apps I have set it as a "Done" button because when the user has finished they can press this and it will drop the keyboard away. To set this add this to your code in somewhere like the -(void)viewDidLoad; method.

textFieldName.returnKeyType = UIReturnKeyDone;

That should then give you a blue done button on the keyboard that hides it.

Popeye
  • 11,839
  • 9
  • 58
  • 91