Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out when cursor is moved (UITextView)

Tags:

ios

uitextview

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

like image 275
H Bellamy Avatar asked Aug 31 '13 21:08

H Bellamy


1 Answers

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;
}
like image 108
Mick MacCallum Avatar answered Oct 25 '22 08:10

Mick MacCallum