How to hide the keyboard in objective-c

I have a simple view with a text box and a UIButton. When I press UIButton, I just want to hide the keyboard that is currently in the view. Is this a simple delegate that I can add to the controller or something more complex?

From the answers that exist on SO, I have not found one that has a complete solution for this context. Any help would be great!

+3
source share
2 answers

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

+14
source

This is how you hide the UITextField when you press the back button:

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

   // do whatever you have to do

   [textField resignFirstResponder];
   return YES;
}

This is how you hide when you press UIButton:

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

   // do whatever you have to do

   [textField resignFirstResponder];
}
+4

Source: https://habr.com/ru/post/1790855/


All Articles