问题描述
|
我在搜索数字键盘的“完成”按钮,然后看到了这个问题:
如何在iPhone数字键盘上显示“完成”按钮
我将Archie的答案代码复制到了我的代码中,并在此区域收到2条警告:
- (void)textFieldDidBeginEditing:(NSNotification *)note {
[self updateKeyboardButtonFor:[note object]];
}
- (void)keyboardWillShow:(NSNotification *)note {
[self updateKeyboardButtonFor:[self findFirstResponderTextField]];
}
- (void)keyboardDidShow:(NSNotification *)note {
[self updateKeyboardButtonFor:[self findFirstResponderTextField]];
}
警告是:
不兼容的Objective-C类型初始化\'struct NSNotification * \',预期\'struct UITextField * \'
我该如何纠正?我尝试使用UITextField进行切换,但一切都搞砸了
解决方法
正如BoltClock所建议的那样,Archie使用委托方法的名称作为通知处理程序似乎有点奇怪。问题可能源于您必须采用“ 1”协议的事实。如果这样做,请删除观察通知的行,
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(textFieldDidBeginEditing:)
name:UITextFieldTextDidBeginEditingNotification
object:nil];
然后在成为文本字段的委托的同时编辑maketextFieldDidBeginEditing:
方法,
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[self updateKeyboardButtonFor:textField];
}
或者,用其他合适的方法名称重命名textFieldDidBeginEditing:
的出现
, textFieldDidBeginEditing
不是通知,它是委托方法。预期签名为- (void)textFieldDidBeginEditing:(UITextField *)aTextField