如何检测UIKeyboard“退格”按钮触摸UITextField? [英] How to detect UIKeyboard "backspace" button touch on UITextField?

查看:103
本文介绍了如何检测UIKeyboard“退格”按钮触摸UITextField?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测 UIKeyboard 上按下的退格按钮?

How can i detect backspace button pressed on UIKeyboard?

谢谢

编辑:是否有任何键盘委托返回按键值?

EDIT: Is there any keyboard delegate that returns key pressed value?

推荐答案

如果UITextField为空,则不会调用shouldChangeTextInRange委托方法
您可以继承UITextField并覆盖此方法:

if the UITextField is empty, the shouldChangeTextInRange delegate method is not called You can subclass UITextField and override this method:

-(void)deleteBackward;
{
    [super deleteBackward];
    NSLog(@"BackSpace Detected");
}

因为UITextField符合UITextInput协议,所以实现了这个方法,而你可以覆盖它以检测何时按下退格键。
然后,如果检测到退格,您可以编写自己的协议/委托方法来提醒自定义文本字段委托。

since UITextField is compliant to the UITextInput protocol, this method is implemented, and you can override it to detect when backspace is pressed. Then, you can write your own protocol/delegate method to alert your custom textfield delegate if the backspace is detected.

这篇关于如何检测UIKeyboard“退格”按钮触摸UITextField?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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