【问题标题】:UIKeyboardWillShowNotification from custom class issue来自自定义类问题的 UIKeyboardWillShowNotification
【发布时间】:2013-04-26 04:34:25
【问题描述】:

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

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

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

【问题讨论】:

  • 您是否在自定义单元格类中为 UIKeyboardWillHideNotification 编写了 addObserver 通知?因为你已经给出了 removeObserver:self 这意味着 Observer 也应该在同一个类中。

标签: ios uitextfield uikeyboard


【解决方案1】:

这样试试

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

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

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

它可能会帮助你。

【讨论】:

    【解决方案2】:

    您好 Ganesh,感谢您的回答。我删除了 resignFirstResponder 并将 firstResponder 直接传递给下一个文本字段。这可以防止键盘消失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多