我有一个带有文本字段的自定义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对象。有什么办法可以解决这个问题?
最佳答案
这样尝试
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
并检查此链接textFieldShouldBeginEditing + UIKeyboardWillShowNotification + OS 3.2
它可能会帮助您。