0

I just made a UITextView and added it to my header file, and synthesized it in my .m file. Now I am trying to make a UILabel update every time a character is added to the UITextView, but it just doesn't work.

I used the code:

- (void)textViewDidChange:startTyping{
    _viewTyping.text = _startTyping.text;
}

My UITextView 'startTying' allow me to type in it, but the UILabel, _viewTyping, never updates. Any thoughts?

BTW, I also tried the same command using IBAction, but for some reason I can't connect the UITextView anywhere is my .m file?

3 Answers 3

2

I have tried both the delegate methods of UITextView both are working

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    _viewTyping.text=textView.text;
    return YES;
}

- (void)textViewDidChange:(UITextView *)textView
{
    _viewTyping.text=textView.text;
}

First Delegate function updates the label one character latter. And the second one updates as it is.

1

Use the UITextView delegate method:

-(void)textViewDidChange:(UITextView *)textView
{
      _viewTyping.text = _startTyping.text;
}

Did you set the delegate to self?

First declare the delegate:

@interface YourViewController ()<UITextViewDelegate>

Second set to self

 self.textView.delegate = self;
6
  • Also make sure that your textView's delegate is your .m file, so the message gets sent.
    – Mark
    Jul 8, 2013 at 3:48
  • Hi, thanks for the answers... I'm a novice and trying to keep up: how do I 1) set delegate to self, and 2) make sure my textView's delegate is my .m file?
    – jake9115
    Jul 8, 2013 at 3:52
  • @interface YourViewController ()<UITextViewDelegate> Jul 8, 2013 at 3:56
  • self.textView.delegate = self; Jul 8, 2013 at 3:57
  • Put self.textView.delegate = self; in viewDidLoad Jul 8, 2013 at 3:58
1

Why do you use _viewTyping? Shouldn't it be self.viewTyping?

Also, check if it is nil. It probably is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.