ios - 来自自定义类问题的 KeyboardWillShowNotification

标签 ios uitextfield uikeyboard

我有一个带有文本字段的自定义 UITableViewCell。单元格的文本字段设置为调用委托(delegate)函数。 里面

  -(BOOL)textFieldShouldReturn:(UITextField *)textField{

                 [[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];

                  [[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];



                   if(textField == fromTF){

                        fromTF.text = [[[fromTF.text substringToIndex:2] stringByAppendingString:@":"] stringByAppendingString:[fromTF.text substringFromIndex:2]];
                        [toTF becomeFirstResponder];
                        return YES;
                    }
                    if(textField == toTF){
                        [toTF resignFirstResponder];
                        [intTF becomeFirstResponder];
                        return YES;

                      }

             return YES;
} 

这是在我的自定义单元格中调用的委托(delegate)方法。但是在调用时,按下“返回”键时不会删除 UIKeyBoardWillHideNotification addobserver 对象。有什么办法可以解决这个问题吗?

最佳答案

这样试试

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{

  [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

并查看此链接 textFieldShouldBeginEditing + UIKeyboardWillShowNotification + OS 3.2

它可能对你有帮助。

关于ios - 来自自定义类问题的 KeyboardWillShowNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16228829/

相关文章:

ios - 如何检测 iOS 默认键盘类型何时从文本切换为数字

ios - NSTextStorage 里面有长文本。表现

ios - 如何在项目中查找文件

ios - 如何将函数参数从 Objective-C 转换为 Swift?

swift - 更改 View Controller ,同时维护用户输入数据

iphone - 在屏幕顶部显示文本字段的键盘

ios - 点击元素时,Webkit 会遮挡 textarea

swift - UI 测试删除文本字段中的文本

ios - UIPickers 数据不会从 UITextField 显示

iphone - 如何知道 UIkeyboard 是否出现在 iOS 中?