textViewDidEndEditing is not called
Asked Answered
S

3

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.

Skyrocket answered 4/9, 2013 at 7:14 Comment(1)
The method textViewDidEndEditing is getting called when KeyBoard Disappears in other words when user stop typing in the textview and resignfirstresponder is being called.Goop
A
9

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

Azygous answered 4/9, 2013 at 7:18 Comment(0)
P
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;
}
Prize answered 4/9, 2013 at 7:19 Comment(0)
C
0

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

Ceratoid answered 4/9, 2013 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.