我有一個帶文本框的自定義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對象。有沒有辦法解決這個問題?
您是否爲自定義單元類中的UIKeyboardWillHideNotification編寫了addObserver通知?因爲你給了像removeObserver:self這意味着Observer也應該在同一個類中。 – 2013-04-26 05:37:29