如何退出或隐藏键盘?
我有一个选择列表来选择一天,还有一个文本字段来显示所选日期。它会像这样...
如果我选择任何日期,它将像这样...
< img src="https://i.sstatic.net/wB0MY.png" alt="alt text">
文本字段中的十字符号是通过代码实现的....
textField.clearButtonMode=UITextFieldViewModeAlways;
现在我的问题是,在单击此十字时按钮,显示键盘。这就像......
但我想要十字按钮仅用于删除文本字段。键盘不应该来。是否可以?
I have a pick list to select a day and a text field to show the selected date. It will be like this...
If i choose any date, it will be like this....
The cross symbol in text field is acheived by the code....
textField.clearButtonMode=UITextFieldViewModeAlways;
Now my problem is, while clicking on this cross button, a keyboard was displayed. This is like....
But i want the cross button only for erase the text field. The keyboard should not come. Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在您的 UITextFieldDelegate 上,实现方法
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
并返回NO
;On your UITextFieldDelegate, implement the method
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
and returnNO
;在文本字段的“编辑已开始”方法中,添加以下内容:
添加此内容后,该键盘将不会显示。
快乐编码:)
In the textfield's 'Editing did begin' method, add the following:
With this in place, that keyboard won't show up.
Happy coding :)
尝试将该文本字段的可编辑属性设置为 false。
Try setting the editable property of that textfield to false.
正如其他人所说,您可以通过 UITextFieldDelegate 协议和
[texfField resignFirstResponder]
方法隐藏键盘。或者,正如 vfn 建议的那样,您可以完全阻止键盘显示。不过,对于该按钮,您还很年轻,想设置文本字段的
clearButtonMode
属性。要查看可用选项,请阅读以下内容: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/Reference/UITextField.html#//apple_ref/doc/c_ref/UITextFieldViewModeAs others have said, you can hide the keyboard through the UITextFieldDelegate protocol and through a
[texfField resignFirstResponder]
method. Alternatively, as vfn suggested, you can prevent thE keyboard from showing altogether.For that button though, you are young to want to set the
clearButtonMode
property of the text field. To see what your available options are, read this: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/Reference/UITextField.html#//apple_ref/doc/c_ref/UITextFieldViewMode