【问题标题】:textViewDidEndEditing is not called未调用 textViewDidEndEditing
【发布时间】:2013-09-07 14:12:43
【问题描述】:

我是 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

但我没有收到来自textViewDidEndEditingtextViewShouldEndEditing 的任何回复。你知道为什么这些没有被调用吗?

感谢您的回答。

【问题讨论】:

  • 当 KeyBoard 消失时调用 textViewDidEndEditing 方法,换句话说,当用户停止在 textview 中输入并调用 resignfirstresponder 时。
  • @GyanendraSingh:感谢您的评论。

标签: iphone ios uitextview uitextviewdelegate


【解决方案1】:

textViewDidEndEditing 在 textfield 退出其第一响应者时调用,当键盘消失时。

【讨论】:

    【解决方案2】:

    确保您已从 .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;
    }
    

    【讨论】:

      【解决方案3】:

      确保您的委托已附加到您的 XIB 文件中 TextView 如果它在 XIB 文件中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-04-06
        • 2011-09-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-01
        相关资源
        最近更新 更多