UITextView scrolling to last line automatically?

Discussion in 'iOS Programming' started by imho, Aug 1, 2008.

  1. imho macrumors newbie

    Jul 31, 2008
    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...
  2. imho thread starter macrumors newbie

    Jul 31, 2008
  3. edwardp macrumors newbie

    Apr 1, 2006
    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)];

Share This Page