ios点击窗口空白地方收回软键盘
要将nib的 view 的custom class 设置为UIControl 才行, 然后将其Touch Down 与action 连接在一起,
-(IBAction)hideKeyboard:(id)sender
{
[[UIApplicationsharedApplication] sendAction:@selector(resignFirstResponder) to:nilfrom:nilforEvent:nil];
}
IOS 中点击(return)键隐藏键盘代码
.h文件委托<UITextFieldDelegate>
例如:
@interface ViewController :UIViewController<UITextFieldDelegate>
并实现以下方法:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (nameTextField == textField) {
[nameTextField resignFirstResponder];
}
return YES;
}
并且指定UITextField的属性delegate指定为UITextFieldDelegate