2
votes

Trying to increase the size of a UITextView programmatically depending on what text has been inputted into it. The problem is, textViewDidChange: will only recognize new line characters if I input something after inputting them. For example, I'm trying to input the following:

Hi, my\n name is Jimmy.

This is what I'll get if I print this in NSLog in textViewDidChange:

Log: H
Log: Hi
Log: Hi,
Log: Hi, m
Log: Hi, my
Log: Hi, my (here goes the new line, but it's not recognized)
Log: Hi, my
 n (it's recognized on this line, only after something is inputted after it).

If I try to input two newlines, only the first one will be recognized and only after I input the second one. Is this some sort of a bug or am I missing something, is there a way to fix this? This used to work properly on iOS 6.

EDIT -- To clarify the problem a bit more, I do get notified that the text has been changed, the problem is the new text is an empty character instead of new line.

EDIT -- It seems that currently the only proper way to find the fitting size for UITextView is by using its sizeThatFits: method while passing it the bounding size. Also if you're changing UITextView's proportions programmatically, it would be wise to remove any autoresizing masks from it.

1

1 Answers

3
votes

Works for me on both iOS 6 and iOS 7. Keep in mind that NSLog will sometimes not show new lines at the end of log like you would expect, so try to log something else after textView.text, for example:

- (void)textViewDidChange:(UITextView *)textView
{
    NSLog(@"TextView text changed to: \"%@\"", textView.text);
}

If it really doesn't log new lines, then it does sound like a bug that you should report.