Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

imho

macrumors newbie
Original poster
Jul 31, 2008
29
0
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...
 

edwardp

macrumors newbie
Apr 1, 2006
2
0
I had the same problem and I solved it by getting the previous scroll position and reseting it after updating the "text"

Code:
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)];
...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.