textViewDidEndEditing is called when textfield resigns its first responder, when the keyboard disappears.
textViewDidEndEditing is not called
-
27-06-2022 - |
Frage
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.
Lösung
Andere Tipps
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;
}
MAke Sure that your delegate is attched in your XIB file with your TextView if it is in XIB file.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow