找出光标移动的时间(UITextView) [英] Find out when cursor is moved (UITextView)

查看:90
本文介绍了找出光标移动的时间(UITextView)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITextView,其委托设置为我的视图控制器



我想帮助您找出如何通过委托方法查找子类化移动光标时选择器和什么不是。



我试过 -textViewDidChange -textViewDidChangeSelection 在所有其他委托方法中,但在文本视图中移动光标时不会调用它们...



那么如何在我的 UITextView 中移动插入符号并在必要时对其进行操作(运行一些代码)



<这可能看起来像一个不切实际的问题,但我有一个场景,我需要在光标向上或向下移动时更新标签,所以我想图



谢谢,我希望我尽可能清楚

解决方案

只是为了扩展@ rmaddy的评论。您将需要使用 UITextViewDelegate 方法-textViewDidChangeSelection:,当文本视图中的选定范围发生变化时收到通知。从那里,您可以访问 NSRange 表示通过文本视图的 selectedRange 属性选择文本。

   - (void)textViewDidChangeSelection:(UITextView *)textView 
{
NSRange range = textView.selectedRange;
}


I have a UITextView that has its delegate set to my view controller

I would like to your help in figuring out how to find out, through delegate methods, subclassing, selectors and what not, when the cursor is moved.

I've tried -textViewDidChange and -textViewDidChangeSelection among all other delegate methods but they don't get called when the cursor was moved within the textview...

So how can I discover when the caret is moved in my UITextView and act upon it as necessary(run some code)

This may seem like an unpractical question but I have a scenario where I need to update a label when the cursor is moved up or down so I would like to fig

Thanks, I hope I've been as clear as possible

解决方案

Just to expand on @rmaddy's comment. You'll want to use the UITextViewDelegate method -textViewDidChangeSelection: to be notified when the selected range in the text view changes. From there, you can access the NSRange representing the selection of text via the text view's selectedRange property.

- (void)textViewDidChangeSelection:(UITextView *)textView
{
    NSRange range = textView.selectedRange;
}

这篇关于找出光标移动的时间(UITextView)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆