我正在尝试将文本字段设置为委托以在按下返回时隐藏键盘
[self.velocityTextField setDelegate:self];
这是编译,但它给了我一个语义。正确的方法是什么?
以下是隐藏键盘的方法:
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
即使您
实现textFieldShouldReturn
视图控制器(自身)不是 UITextField 委托,也可以通过以下方式修改控制器定义:
@interface YourViewController : UIViewController <UITextFieldDelegate>
@end
这就是你得到这个Sending 'viewController *const__strong' parameter of incompatible type 'id<uiTextFieldDelegate>'
的原因