在UIViewController<UITextFieldDelegate>中可以这样实现
在UIView中也可以这样,记得设置UITextField的实现协议。
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.txtSearch resignFirstResponder];
}
#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldClear:(UITextField *)textField{
[textField resignFirstResponder];
textField.text = @"";
return NO;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
textField.text = @"";
return NO;
}