如何隐藏默认键盘
我在表单上添加了 5 个 UITextField。 其中一个文本字段用于输入出生日期。 因此,当触摸该特定文本字段而不是显示默认键盘时,需要显示日期选择器。
我尝试了以下操作:
- (void)textFieldDidBeginEditing:(UITextField *)textField{
[textField resignFirstResponder];
[self showDatePicker];//this is my own function to display 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.
I tried the following:
- (void)textFieldDidBeginEditing:(UITextField *)textField{
[textField resignFirstResponder];
[self showDatePicker];//this is my own function to display datepicker.
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
虽然这是一个老问题,但我在寻找同样的问题时来到这里。
这适用于屏幕中呈现的任何数量/嵌套的视图,
后来我找到了更直观的方法,
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,
Later I found more intuitive way to do it,
您可以在
-textFieldShouldBeginEditing:
中处理此问题。如果该方法返回NO,则不会显示键盘。
只需在此方法中显示日期选择器,然后返回 NO。
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.
也许您不应该为此使用 UITextField。 使用普通的 UITableViewCell 并在点击时使用日期选择器推送新的 UIViewController。
Maybe you should not use a UITextField for this. Use a normal UITableViewCell and push a new UIViewController with the datepicker when tapped.
我刚刚解决了同样的问题,
我们尝试了一些方法,最终得到了很多非常可怕的代码和错误。
到目前为止,最简单的选择是仍然有一个
UITextField
,但将其.inputView
设置为DatePicker
现在我们正在尝试找到一个不错的选择提交字段的方式,因为选择器没有像键盘那样的返回按钮。
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 theDatePicker
Now we are trying to find a nice way to submit the field, since the picker has no return button like the keyboards.
辞职第一响应者应该隐藏键盘。 我最好的猜测是,此时 textField 实际上并不是代码中的第一响应者,因此告诉它退出没有任何效果。 也许您应该插入一个
NSLog
语句来检查这一点。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.