I got a search bar and a table view setup in my project. Now I want a nice way of dismissing the keyboard just when the user touches the screen anywhere outside of the search bar.

```
//Search bar tap recognizer
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                               initWithTarget:self
                               action:@selector(dismissKeyboard)];
[tap setCancelsTouchesInView:NO];
[self.tableView addGestureRecognizer:tap];

```

This works so far - if I leave the following line out:

```
[tap setCancelsTouchesInView:NO];

```

The tap recognizer kind of overlaps the `didSelectRowAtIndexPath` method so if I wanted to select a row, I had to sort of slide across the cell to trigger the `didSelectRowAtIndexPath` method.

Anyways with that line if you tap outside of the search bar, the keyboard disappears but the `didSelectRowAtIndexPath` is also triggered - since most of the time the user would just tap in the middle of the screen - right at a cell of the table view.

How can I keep the table view method `didSelectRowAtIndexPath` from being called the first time if the search bar is still "active"? Because I think it's pretty annoying if you just want to dismiss the keyboard and you then the detail view of the tapped cell shows up.