0

I have implemented UITextViewDelegate in my ViewController,

After setting delegate to my TextView as

self.addressTextView.delegate=self;

Now i can only set the text as,

[self.addressTextView setText:@"Tamil Nadu, India"];

I am unable to edit the text using keybord. After Implementing shouldChangeTextInRange method only i am able to edit the content in UITextView.

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

I dont know why?? is shouldChangeTextInRange compulsory if we implementing UITextViewDelegate

Rooban Ponraj A
  • 281
  • 4
  • 20

3 Answers3

0

NO. Its not compulsary. You can set text like that

textView.text = @"Hello";

This method will be call when you are try to write somthing in your text view.

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
  • If it not compulsory, Then why without adding shouldChangeTextInRange, I am unable to edit the textView by keyboard rather than textView.text=@"" – Rooban Ponraj A Sep 11 '13 at 10:03
0

Its not compulsory in the protocol definition, so more than probably something else is going on. From reading that implementing the delegate method mentioned fixes this, its quite possible that your controller's superclass implements the method and only allows the text you've got above. If that's the case, the workaround you've implemented is in fact the easiest way to fix this.

David Doyle
  • 1,716
  • 10
  • 23
0

For your information, everything that must be implemented when you declare that a class follows a protocol will be indicated by the compiler : you will get an error when you build if a method or a property is missing.

LudoZik
  • 917
  • 1
  • 8
  • 20