Ios remove keyboard

I have some text editing fields, as well as a button to display uidatepicker. If I go to uitextedit, the keyboard will appear, but when I press the button, the keyboard is still here ... how to remove it?

thank!

+3
source share
4 answers

You need to use resignFirstResponder, see this similar question .

[myTextField resignFirstResponder];
+9
source

See this answer for the easiest way to do this: An easy way to dismiss the keyboard?

[self.view endEditing:YES];
+5
source

-resignFirstResponder .

+2

There are times when I do not have direct access to the "first responder", so I tend to use a different approach. I have a utility class for the keyboard, among other functions:

+ (BOOL)dismiss:(UIView *)view
{
    if (view.isFirstResponder) {
        [view resignFirstResponder];
        return YES;
    }
    for (UIView *subView in view.subviews) {
        if ([Keyboard dismiss:subView]) // It calling itself, just to be perfectly clear
            return YES;
    }
    return NO;
}

This allows me to simply call, for example: [Keyboard dismiss:self.view]from anywhere within UIViewController.

0
source

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


All Articles