即使UITextField为空,我还能检测到删除键吗? [英] Can I detect the delete key even if the UITextField is empty?

查看:105
本文介绍了即使UITextField为空,我还能检测到删除键吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当UITextField什么都不包含时,按键盘的删除键不会调用任何UITextFieldDelegate的方法。

When UITextField contains nothing, pressing the delete key of keyboard won't call any of UITextFieldDelegate's methods.

如何检测它?

编辑:
似乎没有琐碎的方法来做到这一点。我能找到的最有用的链接是:

There seems no trivial way to do it. The most useful links I can find are:


  1. UITextField:当字段为空时检测Delete键事件的任何方法?

如何在UITextField中按下实际键?

How to get the actual key pressed in a UITextField

简而言之,我的解决方案是在文本字段的开头放置一个永久的SPACE。并进行其他必要的更改(textFieldShouldReturn:,textField:shouldChangeCharactersInRange:replacementString:等。)。

In short, my solution is to put a permanent SPACE at the start of the text field. And make other nesessary changes(textFieldShouldReturn:, textField:shouldChangeCharactersInRange:replacementString:, etc.).

推荐答案

可以放一个按钮在它上面,但是有点脆弱,因为键盘布局可能会随着不同的iOS版本而改变,并且肯定有不同语言的不同键盘布局。

Its possible to put a button over it, but that's a bit fragile since keyboard layout could change with different iOS versions and there certainly are different keyboard layouts for different languages.

查看管理文本字段和文本视图Apple文档。我确定有办法做到这一点。它类似于UITextField实现了一个获取keyevents的协议。其中一个关键事件可能是删除键,因此您可以覆盖接收这些键的任何方法并以此方式获取。

Look at the "Managing Text Fields and Text Views" Apple doc. Im sure there is a way to do this. Its something like a UITextField implements a protocol to get keyevents. One of those key events will probably be a delete key, so you could override whatever method receives these and get it that way.

这篇关于即使UITextField为空,我还能检测到删除键吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆