tags:

views:

2911

answers:

6

i have an uiview and i add a editable UITextView to it

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(5, 5, 219, 47)];
[self addSubview:textView];
textView.font = [UIFont systemFontOfSize:14];

when i type it doesn't go down automatic. anybody got an idea?

A: 

I think you'll have to do

[textView scrollRangeToVisible:[textView selectedRange]];

in textDidChange.

Can Berk Güder
nope that does not do anything
Andy Jacobs
hmm, strange. can you try [textView scrollRangeToVisible:NSMakeRange(textView.text.length, 0)];
Can Berk Güder
doesn't work either
Andy Jacobs
A: 

if found a solution

i put the textview into a view and set the view to clipToBounds = YES then i put the textView to a height of 70

that fixed the problem.

very strange solution, but it finally works :)

Andy Jacobs
If 70 is lower than your UITextView's original height then it gets clipped to that value an probably by coincidence this is exactly what it takes for your case to "autoscroll" to the last line. It's a little too hackish :)
MihaiD
A: 

wow, that work for me.... any ideas why?

nico
+2  A: 

Just figured out that you must use a length > 0. Ie

NSRange range = NSMakeRange(textView.text.length - 1, 1);
[textView scrollRangeToVisible:range];

Worked for me anyway.

Martin Wickman
Thanks, this was helpful. You also need to check if textView.text.length > 0.
z s
A: 

To scroll to the end of the buffer I tried

[textView scrollRangeToVisible:NSMakeRange([textView.text length]-1, 1)];

But nothing happened. Instead this works

textView.selectedRange = NSMakeRange(textView.text.length - 1, 0);
Frank Hintsch