UITextView 拦截对 setSelectedRange 的调用?
如果点击 UITextView,就会设置 selectedRange 属性。我想拦截该呼叫并可能更改位置。有什么办法可以做到这一点吗?
我尝试
-(void) setSelectedRange: (NSRange) theRange
在我的子类中实现。如果我设置范围,这会很好地拦截它。但是,如果 Apple 的代码正在执行设置(如点击时发生的情况),我的子类 setSelectedRange 方法不会触发。
谢谢
If you tap a UITextView, the selectedRange property is set. I want to intercept that call and possibly change the location. Is there any way to do that?
I tried implementing
-(void) setSelectedRange: (NSRange) theRange
in my subclass. This intercepts it just fine if I am setting the range. But if Apple's code is doing the setting (as happens with a tap), my subclass setSelectedRange method does not fire.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每当选择更改时,
UITextView
的实例都会向其委托发送-textViewDidChangeSelection:
通知,因此您可以在控制器中实现该通知(不要忘记将其设为文本视图的当然是委托),并让控制器操作selectedRange
属性本身。Instances of
UITextView
send a-textViewDidChangeSelection:
notification to their delegate whenever the selection changes, so you could implement that in your controller (don't forget to make it the text view's delegate of course), and have the controller manipulate theselectedRange
property itself.