2

In my project I have to use UITapGestureRecognizer in viewDidLoad, but if i use it, then the didSelectRowAtIndexpath method doesn't work. I have also done so that "The Tap" method is called in a method and that method is called in viewDidLoad but still same problem occurs didSelectRowAtIndexpath method doesn't work.

Please tell me how to use that method in viewDidLoad so that both will work at the same time without any problems.

-(void)searchTap
{

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                                   initWithTarget:self
                                   action:@selector(dismissKeyboard)];

    [self.view addGestureRecognizer:tap];

}
- (void) dismissKeyboard
{

    [mySearchBar resignFirstResponder];

}

I want to call this method on viewDidLoad. but when i do [self searchTap]; the didSelectRowAtIndexpath method stops working.

Leistungsabfall
  • 6,368
  • 7
  • 33
  • 41
  • 1
    add tap gesture to a specific view not self.view if you do so than it is possible that your button and table didselectrow may not respond. Please show some code. – Smile Dec 23 '15 at 06:11
  • 1
    Possible duplicate of [UITapGestureRecognizer breaks UITableView didSelectRowAtIndexPath](http://stackoverflow.com/questions/8192480/uitapgesturerecognizer-breaks-uitableview-didselectrowatindexpath) – Muneeba Dec 23 '15 at 06:14
  • but i want tapgesture on self.view. –  Dec 23 '15 at 06:18
  • 1
    http://stackoverflow.com/questions/21517559/tableview-is-hiding-due-to-a-gesturerecognizer-before-it-can-execute-didselectro – Rohit Khandelwal Dec 23 '15 at 06:18
  • 1
    seems you just need to call the selector dismissKeyboard in the didSelectRowAtIndexPath. UITableView have a set of gesture recognizers once it is loaded and those will override the gestures u have defined explicitly. If you have a high end requirement use gesture recognizers with its(table view's) superview or with custom view. Adding gestures which not already included in the UITableview doesn't make sense. – Alex Andrews Dec 23 '15 at 06:22
  • 1
    Instead of adding tap gesture, put a button in that cell, on tap of that button call searchTap method. Once this method completes, didSelectRowAtIndexPath will automatically be called. – Vikas Mishra Dec 23 '15 at 06:25

0 Answers0