Touches began in UITableViewController

sumderungHAY picture sumderungHAY · Jun 9, 2011 · Viewed 7.7k times · Source

I am defining this method in my UITableViewController subclass:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    NSLog(@"touch began");
}

but it's not being triggered. UIViewController is a subclass of UIResponder so it should work, right? Thanks

Answer

Scott Chin picture Scott Chin · May 12, 2012

If you are trying to dismiss a keyboard in a UITableViewController, a decent solution is to call resignFirstResponder in the tableView delegate's didSelectRowAtIndexPath method.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [myTextField resignFirstResponder];

    // Rest of your actual didSelectRowAtIndexPath code ...
}