[英](iOS) How do I get notified when the keyboard's back button is pressed?
I'm trying to determine when the keyboard's back button is pressed. 我试图确定何时按下键盘的后退按钮。 When there is text in the text field, this is easy.
当文本字段中有文本时,这很容易。 I simply use the delegate method - (BOOL)textField:(UITextField *)aTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string.
我只使用委托方法-(BOOL)textField:(UITextField *)aTextField shouldChangeCharactersInRange:(NSRange)range replaceString:(NSString *)string。 The problem is when the text field is empty and the back button is pressed, this method isn't called.
问题是当文本字段为空并且按下后退按钮时,不会调用此方法。
Does anyone know how to get notified even when the text field is empty? 有没有人知道即使文本字段为空也如何得到通知?
Could you default in a single space to the empty field when you begin editing (and the field is empty) so that the backspace becomes a normal event? 开始编辑时(字段为空),您可以在单个空格中默认为空白字段吗,以使退格键成为正常事件吗? You could remove the space when leaving the field and/or the first normal character is typed.
您可以在离开字段和/或输入第一个普通字符时删除空格。 Bit of a hack but I don't think you'll get to it any other way.
有点骇人听闻,但我认为您不会以其他任何方式解决它。
Check out this answer.. 看看这个答案。
Receive iPhone keyboard events 接收iPhone键盘事件
In your keyPressed function, check to see if the textfield value has any content; 在keyPressed函数中,检查textfield值是否具有任何内容;
In the delegate method: 在委托方法中:
(BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)string (布尔)textView:(UITextView *)textView应该ChangeTextInRange:(NSRange)范围替换Text:(NSString *)字符串
keep the earlier string and compare it with the string, if count of string is 1 less than the previous modified string it means delete is pressed. 保留先前的字符串并将其与该字符串进行比较,如果字符串的计数比先前修改的字符串小1,则表示已按下删除键。 Otherwise store string into earlier string.
否则,将字符串存储到较早的字符串中。 hope this will help you.
希望这会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.