我是iOS开发的新手。
我已经像这样编写了头文件
@interface TextView : UITextView <UITextViewDelegate, UIPopoverControllerDelegate>
TextView.h。
实施文件代码如下:
- (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
}
当我开始在UITextView
中输入字符时,我收到了来自
textViewShouldBeginEditing
。textViewDidBeginEditing
。shouldChangeTextInRange
。textViewDidChange
。但我没有得到textViewDidEndEditing
或textViewShouldEndEditing
的任何回复。你知道为什么这些没有被调用吗?
感谢您的回答。
答案 0 :(得分:9)
当键盘消失时,当textfield重新启动第一个响应者时,会调用textViewDidEndEditing。
答案 1 :(得分:3)
确保您已从.xib
正确链接了您的委托并按原样使用以下方法,看看它将被称为
-(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;
}
答案 2 :(得分:0)
MAke确保您的委托与TextView一起附在您的XIB文件中(如果它在XIB文件中)。