1

I have aUITextView. I would like to have a way of updating aUILabel as the user times to indicate how many remaining characters are permitted?

In theViewController theUITextView is referenced as IBOutlet UITextView *message;

I have tried looking at the show connections inspector and I don't see an edit changed option.

I looked at this example UITextField text change event

But it seemed to apply toUITextField notUITextView

Community
  • 1
  • 1
Jack Shultz
  • 2,031
  • 2
  • 30
  • 53
  • 3
    [`[ textViewDidChange:]`](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITextViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/UITextViewDelegate/textViewDidChange:) – The Paramagnetic Croissant Jun 09 '15 at 11:55
  • https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITextViewDelegate_Protocol/index.html – Szu Jun 09 '15 at 11:56

1 Answers1

1

This should help:

- (void)textViewDidChange:(UITextView *)textView{

    NSString *stringCount = self.textView.text;
    int count = (int) stringCount.length;
    //assumes you have a label, see the attached gif
    self.label.text = [NSString stringWithFormat:@"TextView count is: %d",count];

    NSString *stringcount222 = self.textview222.text;
    int count222 = (int) stringcount222.length;
    self.label222.text = [NSString stringWithFormat:@"No. 2 count is: %d", count222]; 

}

You need to select the TextView that you are using and control+drag to the ViewController icon and select Delegate:

enter image description here

The you should be able to get a result like this:

enter image description here

App Dev Guy
  • 5,396
  • 4
  • 31
  • 54