-(void)viewDidLoad
{
self.view.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fingerTapped:)];
[self.view addGestureRecognizer:singleTap];
}
-(BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
-(void)fingerTapped:(UITapGestureRecognizer *)gestureRecognizer
{
[self.view endEditing:YES];
}原文