6

I'm new to iOS development.

I have written header file following like this

@interface TextView : UITextView <UITextViewDelegate, UIPopoverControllerDelegate>

in TextView.h.

The implementation file code is following :

- (BOOL)textViewShouldBeginEditing:(TextView *)textView
{
    ZWLog(@"called should begin edit");
    return YES;
}

- (void)textViewDidBeginEditing:(TextView *)textView
{
    ZWLog(@"called did begin edit");
}

- (BOOL)textViewShouldEndEditing:(TextView *)textView
{
    ZWLog(@"called should end editing");
    return YES;
}

- (void)textViewDidEndEditing:(TextView *)textView
{
    ZWLog(@"view did end edit");
    return YES;
}

- (BOOL)textView:(TextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    //my own code
    return YES;
}

- (void)textViewDidChange:(TextView *)textView
{
   //my own code
}

When i start typing a character in UITextView, I got response from

  • textViewShouldBeginEditing.
  • textViewDidBeginEditing.
  • shouldChangeTextInRange.
  • textViewDidChange.

But I didn't get any response from textViewDidEndEditing or textViewShouldEndEditing. Do you have any idea why these are not getting called?

Thanks for your answers.

Tom Tanner
  • 9,244
  • 3
  • 33
  • 61
Kirubachari
  • 688
  • 11
  • 27
  • The method textViewDidEndEditing is getting called when KeyBoard Disappears in other words when user stop typing in the textview and resignfirstresponder is being called. – Gyanendra Singh Sep 04 '13 at 07:17

3 Answers3

9

textViewDidEndEditing is called when textfield resigns its first responder, when the keyboard disappears.

Nico
  • 513
  • 7
  • 13
3

make sure you've linked your delegate properly from .xib

and use the below methods as it is and take a look it will get called

-(BOOL)textViewShouldEndEditing:(UITextView *)textView
{
    ZWLog(@"textViewShouldEndEditing");
    return TRUE;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    ZWLog(@"shouldChangeTextInRange");
    // Any new character added is passed in as the "text" parameter
    if ([text isEqualToString:@"\n"])
    {
        [textView resignFirstResponder];
        return FALSE;
    }

    // For any other character return TRUE so that the text gets added to the view
    return TRUE;
}
D-eptdeveloper
  • 2,430
  • 1
  • 16
  • 30
0

MAke Sure that your delegate is attched in your XIB file with your TextView if it is in XIB file.

user1673099
  • 3,293
  • 7
  • 26
  • 57