PDA

View Full Version : UITextView scrolling to last line automatically?




imho
Aug 1, 2008, 02:57 PM
Does anyone know how to make UITextView stay scrolled at the last line? Kinda like new lines being added and i want the view to just scroll one line and display the new line at the bottom. Something like XCode's debug console...

UITextView seem to insist on doing the reverse of what i wanted. It stays stuck to the first line at the top.

I tried scrollRangeToVisible in order to show the last line, but it scrolls from the start to the end every time a call is made... That kinda makes the whole thing twitchy and vommit-inducing...



imho
Aug 5, 2008, 04:13 AM
bumped.

nobody?

edwardp
Aug 14, 2008, 03:52 AM
I had the same problem and I solved it by getting the previous scroll position and reseting it after updating the "text"

UITextView *tv;
...
CGPoint p = [tv contentOffset];
tv.text = [NSString stringWithFormat:@"%@\n%@", tv.text, @"New line"];
[tv setContentOffset:p animated:NO];
[tv scrollRangeToVisible:NSMakeRange([tv.text length], 0)];
...