检测空白文本字段上 UITextField 中的退格键
可能的重复:
检测 UITextField 中的退格键
我正在尝试检测我的 UITextfield 上的退格键事件,该事件为空。我看到了这个,但无法弄清楚。任何详细的答案或代码片段都会有帮助
Possible Duplicate:
Detect backspace in UITextField
I am trying to detect the backspace key envent on my UITextfield which is empty. I saw this but could not figure it out. Any elaborate answer or code snippet would be helpful
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现这是不可能的。
当 UITextField 为空时,不会调用以下委托方法。
我通过在字段中不断有一个空格来克服这个问题,当我检测到退格键并且字段只包含一个空格时,我在委托方法中返回 NO。
从视觉上看,这与字段为空一样好,并且它是不在空字段上调用委托方法的解决方法。
希望有帮助。
I've found it not to be possible.
When the UITextField is empty, the following delegate method isn't called.
I conquered this by constantly having a space in the field, and when I detect a backspace and the field only contains a space, I return NO in the delegate method.
Visually, this is as good as the field being empty, and it's a workaround to the delegate method not being called on an empty field.
Hope that helps.
:) 只是为了标题“检测退格”,我在其中使用
UIKeyboardTypeNumberPad
。今晚我也遇到了同样的问题,下面是我的代码来找出它:
因为使用
UIKeyboardTypeNumberPad
,用户只能输入数字或退格键,所以当字符串长度为0时,它必须是退格键钥匙。希望以上内容能够给大家带来一些帮助。
:) just for the title "Detect backspace", where I use
UIKeyboardTypeNumberPad
.I also meet the same question tonight, and following is my code to find it out:
Because with
UIKeyboardTypeNumberPad
, user can only input Number or backspace, so when the length of string is 0, it must be backspace key.Hope the above will do some help.