自定义类问题的UIKeyboardWillShowNotification
问题描述:
我有一个带文本框的自定义UITableViewCell。单元格的文本字段设置为调用委托函数。 里面自定义类问题的UIKeyboardWillShowNotification
-(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;
}
这是委托方法被称为我的自定义cell.However调用时,当按下“返回”键,不会删除该UIKeyBoardWillHideNotification的addObserver对象。有没有办法解决这个问题?
答
你好Ganesh谢谢你的答案。我删除了resignFirstResponder并将第一个响应者直接传递给下一个文本字段。这防止了键盘消失。
答
尝试这样
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
,并检查该链接textFieldShouldBeginEditing + UIKeyboardWillShowNotification + OS 3.2
它可以帮助你。
您是否为自定义单元类中的UIKeyboardWillHideNotification编写了addObserver通知?因为你给了像removeObserver:self这意味着Observer也应该在同一个类中。 – 2013-04-26 05:37:29