3

I have a simple view with a textbox and a UIButton. When I click the UIButton I simply want to hide the keyboard that is currently in the view. Is this a simple delegate I can add to the controller or something more complex?

Of the answers that exist on SO already I haven't found one that has a full solution for this context. Any help would be great!

Nicholas Riley
  • 43,532
  • 6
  • 101
  • 124
Toran Billups
  • 27,111
  • 40
  • 155
  • 268
  • possible duplicate of [Hide keyboard when user touches uiview](http://stackoverflow.com/questions/963571/hide-keyboard-when-user-touches-uiview) – Nicholas Riley Feb 09 '11 at 01:15

2 Answers2

14

Try something like: [TextField resignFirstResponder]; Where TextField is the name of your text field.

joshim5
  • 2,292
  • 4
  • 28
  • 40
4

This is how you hide the UITextField when you hit the return button:

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

   // do whatever you have to do

   [textField resignFirstResponder];
   return YES;
}

This is how you hide when you hit an UIButton:

- (void)hideTextField:(UITextField *)textField {

   // do whatever you have to do

   [textField resignFirstResponder];
}
Andre Cytryn
  • 2,506
  • 4
  • 28
  • 43