Here’s my situation: I’ve got a UISearchBar and a UITableView in a Navigation Controller. When the user taps in the search bar, the keyboard pops so the user can type a search string, as shown here:

But the keyboard obscures the list, and so I want to make it so that if the user taps the table, the keyboard goes away, and I’m having a surprising amount of difficulty.
- If I use a TapGestureRecognizer, I can tell if the user taps anywhere, but then when they tap on the table, the normal table events don’t work.
- I tried something else (can’t remember what now), and I got the event if the user taps the table, but not tap and drag, which is common, and so that’s not quite enough.
What I want is something like a TouchDownInside event on the table itself, so I can dismiss the keyboard when the table gets user input of any kind, but this doesn’t seem to exist. What’s the best way to do this?
An easy solution would be to catch when the UITableView is scrolling, as the UITableView extends the UIScrollView you can look for the scrollViewDidScroll: and make the search bar resign the first responder to make the keyboard go away, same can be done with scrollViewWillBeginDragging: method
Implement this on you UITableViewDelegate as it behaves as the delegate of your UITableView
More information at
http://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/