How to hide default keyboard

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 08:48:40

Though this is an old question, I came here while I was searching for the same.

This will work for any number/nesting of views presented in the screen,

- (void) hideKeyboard: (UIView *) view {
    NSArray *subviews = [view subviews];
    for (UIView *subview in subviews){
        if ([subview isKindOfClass:[UITextField class]]) {
            [subview resignFirstResponder];
        }
        [self hideKeyboard: subview ];
    }
}

Later I found more intuitive way to do it,

[self.view endEditing:YES];

You can handle this in -textFieldShouldBeginEditing:.

If this method returns NO, the keyboard will not be displayed.

Simply show the date picker in this method and then return NO.

Maybe you should not use a UITextField for this. Use a normal UITableViewCell and push a new UIViewController with the datepicker when tapped.

I've just been working through this same problem,

We tried a few things and ended up with a lot of really horrible code and bugs along the way.

The simplest option by far is to still have a UITextField, but to set it's .inputView to the DatePicker

Now we are trying to find a nice way to submit the field, since the picker has no return button like the keyboards.

Resigning the first responder ought to hide the keyboard. My best guess is that textField isn't actually the first responder at this point in the code, so telling it to resign has no effect. Perhaps you should insert an NSLog statement to check that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!