Search code examples
ioscocoa-touchuitextviewuitextviewdelegate

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


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?


Solution

  • 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.