-1

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]?

BlueMandora
  • 154
  • 1
  • 6

2 Answers2

0

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.

Teo
  • 3,394
  • 11
  • 43
  • 73
0

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];
}
Utsav Parikh
  • 1,216
  • 7
  • 14