删除(不是Backspace)不会触发UITextViewDelegate的shouldChangeTextInRange [英] Delete (not Backspace) doesn't fire UITextViewDelegate's shouldChangeTextInRange
问题描述
使用外部键盘时,当我按Backspace键(向后删除")时,我的 UITextView
会触发一条 shouldChangeTextInRange
消息,但如果我按Delete键("forward delete"),那么即使视图的文本按预期更改,也根本不会调用该方法.万一有问题,我正在使用Swift和最新的iOS模拟器.
When using an external keyboard, my UITextView
fires a shouldChangeTextInRange
message just fine when I press the Backspace key ("backward delete"), but if I press Delete ("forward delete") then the method is never called at all, despite the view's text changing as expected. In case it matters, I'm using Swift and the latest iOS simulator.
如果这是预期的行为,有人可以指出我的解释性文档吗?
If this is expected behavior, can someone point me to the documentation that explains it?
更重要的是,有什么解决方法吗?
More importantly, is there a workaround?
提交了rdar://18909378.使用cmd +退格键和opt +退格键时,我也发现了相同的行为.非常烦人!
submitted rdar://18909378. I've also discovered the same behavior when using cmd+backspace and opt+backspace. Very annoying!
推荐答案
我仍然在iOS 10上看到此问题.我想出的最佳解决方法是听该字段的 UIControlEventEditingChanged
>事件并从此处获取 textField.text
.这将为您提供更新的内容,但不允许您像 shouldChangeCharactersInRange
那样执行删除操作.
I'm still seeing this issue on iOS 10. The best workaround I've come up with is to listen to the field's UIControlEventEditingChanged
event and grab textField.text
from there. This gives you the updated contents, but doesn't allow you to prevent the delete action like shouldChangeCharactersInRange
does.
这篇关于删除(不是Backspace)不会触发UITextViewDelegate的shouldChangeTextInRange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!