Hide keyboard when scroll UITableView Hide keyboard when scroll UITableView ios ios

Hide keyboard when scroll UITableView


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


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];}


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