Delete (not Backspace) doesn't fire UITextViewDelegate's shouldChangeTextInRange

…衆ロ難τιáo~ 提交于 2020-12-29 10:09:44

问题


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?

Edit: submitted rdar://18909378. I've also discovered the same behavior when using cmd+backspace and opt+backspace. Very annoying!


回答1:


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.



来源:https://stackoverflow.com/questions/26785466/delete-not-backspace-doesnt-fire-uitextviewdelegates-shouldchangetextinrange

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!