Is there a delegate request when the text is changed in a UITextView?

When I install my UITextViewprogrammatically as follows:

[self.textView setText:@""];

The delegate method is textViewDidChange:not called. Is there any way to find this without subclassing UITextView?

+4
source share
3 answers

When manually setting text UITextViewwith code, the method is textViewDidChange:not called. (If you have a text view installed delegate, it will be called up when the user edits it).

One possible way to solve the problem would be to manually call it textViewDidChange:anytime you edit the text. For instance:

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

, .

+14

@rebello95, . , -

-(void)whereIManuallyChangeTextView
{//you don't actually have to create this method. It simply wherever you are setting the textview to empty
  [self.textView setText:@""];
  [self respondToChangeInTextView:self.textView];
}

- (void)textViewDidChange:(UITextView *)textView
{
  //...some work and then
  [self respondToChangeInTextView:textView];
}

-(void)respondToChangeInTextView:(UITextView *)textView
{
  //what you want to happen when you programmatically/manually or interactively change the textview
}

, .

+3

use this instead: ( this will not reset the current text )

[self.textView insertText:@"something"];

this will call the delegate and add the text where the cursor is. Of course, if you want to reset all text, you can:

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

or

[self.textView setText:@""];
[self.textView insertText:@"something"];
-1
source

All Articles