views:

1510

answers:

3

OK, I'm having some problem with the UITextView. Here's the issue: I add some text to a UITextView. The user then double clicks to select something. I then change the text in the UITextView (programatically as above) and the TextView scrolls to the bottom of the page where there is a cursor. However, that is NOT where the user clicked. It ALWAYS scrolls to the bottom of the UITextView regardless of where the user clicked. So here's my question. How do I force the UITextView to scroll to the top every time I change the text. I've tried contentOffset and scrollRangeToVisible. Neither work. Any suggestions would be appreciated. Thanks, Sam

A: 

Try this to move the cursor to the top of the text.

NSRange r  = {0,0};
[yourTextView setSelectedRange:r];

See how that goes. Make sure you call this after all your events have fired or what ever you are doing is done.

John Ballinger
tried it man, no luck. It seems to be something with the firstResponder. Any other suggestions?
Sam
A: 

I'm not sure if I understand your question, but are you trying to simply scroll the view to the top? If so you should do

[textview scrollRectToVisible:CGRectMake(0,0,1,1) animated:YES];

Benjamin Sussman
I'm trying to scroll to the top, but it doesn't work. The problem has been solved over at the iPhone developer forums (for any future readers) https://devforums.apple.com/thread/25158?tstart=0 (developer login required)
Sam
+2  A: 
UITextView*note;
[note setContentOffset:CGPointMake(0, 0) animated:YES];

This does it for me.

Wayne Lo