如何隐藏默认键盘 [英] How to hide default keyboard
问题描述
我在表单上添加了5个UITextField。其中一个文本用于输入出生日期。因此,当触摸该特定文本字段而不是显示默认键盘时,需要显示datepicker。
I have 5 UITextFields added on a form. One of the textfileds is for entering the date of birth. So when that particular textfield is touched instead of displaying the default keyboard, datepicker needs to be displayed.
我尝试了以下内容:
- (void)textFieldDidBeginEditing:(UITextField *)textField{
[textField resignFirstResponder];
[self showDatePicker];//this is my own function to display datepicker.
}
当调用此函数时,会显示datepicker以及日期选择器还会显示默认键盘并隐藏日期选择器。对于这个特定的textfiled,我不知道如何摆脱默认键盘。请帮助我。
when this function is called the datepicker is displayed, along with the date picker the default keyboard is also displayed and that hides the datepicker. I don't know how to get rid of the default keyboard, for this particular textfiled. Please help me.
推荐答案
虽然这是一个老问题,但我在寻找同样的时候来到这里。
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];
这篇关于如何隐藏默认键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!