iOS:如何将密钥发送给UITextField?

我在iOS应用程序中实现了自定义键盘视图。 我有几个使用此键盘的UITextFields。 其中一些UITextFields具有覆盖shouldChangeCharactersInRange委托。 但是,如果我的键盘只是在文本字段中设置文本值,则不会发送shouldChangeCharactersInRange消息。 我想我需要的是实际执行SendKey之类的操作,并将密钥代码发送到UITextField。

有什么建议么?


正如我在这里回答的那样, UITextField符合UITextInput协议。 所以你调用它的方法:

[textField replaceRange:textField.selectedTextRange withText:text];

感兴趣的是: ""会执行退格,当然, " "会做空格。

这应该自动调用shouldChangeCharactersInRange方法。 如果不是,你必须自己做。

如果您要在iOS上创建自定义键盘,则必须执行此操作。


听起来好像键盘负责将shouldChangeCharactersInRange消息发送给UITextField本身,而不是仅仅设置它的值。 让你的键盘计算rangestring的值,然后调用:

if ([[theTextField delegate] textField:theTextField shouldChangeCharactersInRange:range replacementString:string])
    theTextField.text = [theTextField.text stringByReplacingCharactersInRange:range withString:string];
链接地址: http://www.djcxy.com/p/52469.html

上一篇: iOS: How to send key to UITextField?

下一篇: Ways to stream audio (mp3/wav/etc)...Gem/Plugins vs HTML5?