Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(iOS7) Scroll to cursor in UITextView in UITableView in UIScrollView

I have a problem since I updated to iOS7.

I have base UIScrollView horizontally and there is UITableView on it (looks like a navigation style). And I addChild UITextView on UITableView not on the cells.

And it scrolled to UITextView's cursor when typing keyboard. And it works greatly until iOS 6 but not since updating iOS7.

How can I solve this problem?

Thanks.

like image 879
Bright Lee Avatar asked Oct 07 '13 04:10

Bright Lee


1 Answers

Handle textViewDidChangeSelection in UITextViewDelegate:

- (void)textViewDidChangeSelection:(UITextView *)textView {
    [textView scrollRangeToVisible:textView.selectedRange];
}

The exact solution depends on your application, you can handle by subclassing UITextView but I would prefer a decorator pattern here (on UITextViewDelegate protocol).

I hope it helps.

like image 86
imihaly Avatar answered Oct 08 '22 10:10

imihaly