In one of my projects, I needed some kind of click on the tableView to dismiss the keyboard in order to display the underlying tableView. Since UITableView is indeed a UIScrollView, it will respond to scrollView delegate methods. Using these two methods will be rejected if the user clicks on a cell or scrolls through the tableView at all:
IMPORTANT: make sure you use UIScrollViewDelegate in the .h file, as well as UITableViewDelegate and UITableViewDataSourceDelegate !!!
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //remove keyboard if table row is clicked if ([self.firstName isFirstResponder] || [self.lastName isFirstResponder]) { [tableView deselectRowAtIndexPath:indexPath animated:NO]; [self.firstName resignFirstResponder]; [self.lastName resignFirstResponder]; } } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { //remove keyboard if table scrolls if ([self.firstName isFirstResponder] || [self.lastName isFirstResponder]) { [self.firstName resignFirstResponder]; [self.lastName resignFirstResponder]; } }
Doctorg
source share