0

I just have no idea on how its used and cant seem to find any tutorials. Please help! I need a method called every time theres a change in my UITextView. I do appologise but I just have no ideas how targeting works which I assume is how textViewDidChange works.

James Heald
  • 841
  • 1
  • 12
  • 33
  • A simple Google search for __"textViewDidChange tutorial"__ gave me __[this](http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_uitextview_uitextviewdelegate_2/)__ link which you will undoubtedly find helpful. Please, do some research before asking questions like this. – aksh1t Jul 08 '13 at 14:24
  • Check my answer : http://stackoverflow.com/questions/16016729/how-to-detect-keyboard-key-pressed-in-iphone/16016965#16016965 – Nishant Tyagi Jul 09 '13 at 04:41
  • 1
    FWIW, when I google stuff about UITextView now, this question comes up... and this is now being used as a dupe target for other questions. I'd rather read about something on SO than on some ad riddled third party site from 2012, but okay I guess. – jrh Jul 08 '19 at 00:04

2 Answers2

8

First create Delegate of your textView

@interface YourViewController : UIViewController<UITextViewDelegate>

Than set your textView delegate to self

myTextView.delegate = self;

Now you can see change in your textView

-(void)textViewDidChange:(UITextView *)textView
{
    NSLog(@"Dilip : %@",textView.text);
}
Dilip Manek
  • 9,095
  • 5
  • 44
  • 56
  • 1
    This answer works but I'd like to add a bit more of an explanation. The reason why `myTextView.delegate` works to connect `textViewDidChange` is because by making your `ViewController` implement the `UITextFieldDelegate`, your`ViewController` itself now acts as something that can accept method calls like `textViewDidChange`, and I guess that internally `UITextView` looks to see if `delegate` is nil and if it isn't, it calls a function if the (optional) method is present on that object. Coming from a C/C++/C# background this pattern is very foreign but it makes sense after a while. – jrh Jul 08 '19 at 02:18
0

Use the textView Delegate.

First declare the delegate:

@interface YourViewController ()<UITextViewDelegate>

Second set to self

self.textView.delegate = self;
Abdullah Shafique
  • 6,878
  • 8
  • 35
  • 70