禁用 UI 键盘中的特定键
它需要禁用“&”数字和标点符号键盘中的键,那么是否可以禁用 UIKeyboard 中的特定键?
It need to disable '&' key from number and punctuation keyboard, so is it possible to disable a particular key in UIKeyboard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为不可能禁用某个键(除非它是操作键之一,例如返回键),但如果您使用的是 UITextField,则可以使用
- (BOOL)textField:(UITextField *) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
委托方法来查看用户是否按下了 & key 并将其从字符串中删除I don't think it's possible to disable a certain key (unless it's one of the action keys such as the return key) but if you are using a UITextField you can use the
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
delegate method to see if the user pressed the & key and remove it from the string你不能那样做。但是您的选择是:
UITextField
您可以验证用户提交的文本:删除 '&'和/或通知用户不允许使用“&” (更容易)。编辑:您还可以将 UITextField 的“编辑已更改”事件连接到文件所有者的 IBAction 并过滤掉“&”那里。
You cannot do that. However your options are:
UITextField
you can validate the text submitted by user: remove '&' and/or inform user that it is not allowed to use '&' (much easier).EDIT: you can also connect UITextField's "Editing Changed" event to the File's Owner's IBAction and filter out '&' there.
textField 有一种委托方法,您可以根据需要根据特定字符的 ASCII 值来阻止特定字符。该方法可以写如下:
该方法只允许数字和 & 。由用户输入的符号。即使用户按下其他字符,它们也不会被输入。由于它是 textField 的委托方法,因此您无需担心显式调用它。
There is one delegate method for textField in which you can block specific characters if you want based on their ASCII values. The method can be written as follows:
This method will permit only numbers and & symbol to be entered by the user. Even if the user presses other characters they won't be entered. And as it is a textField's delegate method you don't need to worry about calling it explicitly.