0

I have an application which has a UITabBarController and Inside one of its items I have a UITableViewController and I want to add a UITapGestureRecognizer to view of UITableViewController.

Here comes my code:

 - (void)viewDidLoad  
{
[super viewDidLoad];
     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyBoard:)];
        [self.view addGestureRecognizer:tap];
}
- (void)dismissKeyBoard:(id)sender
{
        [self.view endEditing:NO];
}

But dismissKeyBoard is never called! What should I do? and why it is not called?

aakpro
  • 1,538
  • 2
  • 19
  • 53

1 Answers1

1

Without knowing whether you are using Storyboards, which these days most people do, have you dragged touch onto your view? It's just a secondary measure to confirm all bases are covered.

-(void) viewDidLoad{

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyBoard:)];
    [self.view addGestureRecognizer:tap]; 

}

resignFirstResponder is the usual call I make rather than endEditing.

UPDATE Something I have noticed is you are calling "sender" in your dismissKeyboard. Drop that.

-(void) dismissKeyboard{//**NO SENDER**, then it should work

    [self.textField resignFirstResponder];

}
App Dev Guy
  • 5,396
  • 4
  • 31
  • 54