I have a custom tableViewCell which has a textfield inside.
How to dismiss keyboard when tap any place outside the textfields?
Do I have to look through all cells use [cell.textView resignFirstResponder]
?
I have a custom tableViewCell which has a textfield inside.
How to dismiss keyboard when tap any place outside the textfields?
Do I have to look through all cells use [cell.textView resignFirstResponder]
?
No, you can just use:
[self.view endEditing:YES];
endEditing:
Causes the view (or one of its embedded text fields) to resign the first responder status.
Parameters: force
Specify YES to force the first responder to resign, regardless of whether it wants to do so.
Try this code :
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
}
Or you can add a tap gesture recognizer :
UITapGestureRecognizer *tapper;
- (void)viewDidLoad
{
[super viewDidLoad];
tapper = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSingleTap:)];
tapper.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tapper];
}
- (void)handleSingleTap:(UITapGestureRecognizer *) sender
{
[self.view endEditing:YES];
}