Kirubachari
Kirubachari

Reputation: 688

textViewDidEndEditing is not called

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

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.

Upvotes: 6

Views: 7689

Answers (3)

user1673099
user1673099

Reputation: 3299

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

Upvotes: 0

D-eptdeveloper
D-eptdeveloper

Reputation: 2430

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;
}

Upvotes: 3

Nico
Nico

Reputation: 513

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

Upvotes: 9

Related Questions