Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 810
SirRupertIII Avatar asked Aug 27 '14 22:08

SirRupertIII


2 Answers

In swift you could override text var in UITextView class

class MyTextView: UITextView {

    override public var text: String? {
        didSet {
            self.textViewDidChange(self)
        }
    }

}
like image 125
AndyW Avatar answered Oct 04 '22 19:10

AndyW


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.

like image 40
rebello95 Avatar answered Oct 04 '22 19:10

rebello95