Is there a delegate call for when the text is changed on a UITextView?

SirRupertIII picture SirRupertIII · Aug 28, 2014 · Viewed 7.9k times · Source

When I set my UITextView programmatically like this:

[self.textView setText:@""];

The delegate method textViewDidChange: does not get called. Is there a way I can find that without making a UITextView subclass?

Answer

rebello95 picture rebello95 · Aug 28, 2014

When manually setting the text of a UITextView with code, the textViewDidChange: method does not get called. (If you have your text view's delegate set, it will get called when the user edits it, though.)

One possible workaround would be to manually call textViewDidChange: anytime you edit the text. For example:

[self.textView setText:@""];
[self textViewDidChange:self.textView];

Kind of a hackish way of doing it, but it gets the job done.