Hide keyboard when scroll UITableView

You can do this right in Interface Builder. Select your UITableView and open the Attributes Inspector. In the Scroll View section set the Keyboard field to Dismiss on Drag.

enter image description here


Not sure why you need to subclass UITableView for this.

In the view controller that contains the plain UITableView, try adding this:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [searchBar resignFirstResponder];
}

Here is the cleanest way to achieve this in iOS 7.0 and above:

tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;

Or to dismiss interactively when touching:

tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;

Or in Swift:

tableView.keyboardDismissMode = .onDrag

To dismiss interactively:

tableView.keyboardDismissMode = .interactive