Hide keyboard when scroll UITableView
Solution 1:
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
Solution 2:
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];
}
Solution 3:
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.
Solution 4:
Just to add an update to the answers above. The below worked for me in Swift 1.2
tableView.keyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag
or
tableView.keyboardDismissMode = UIScrollViewKeyboardDismissMode.Interactive