touchesBegan method not called in UITableViewController class in iPhone

Confused picture Confused · Jan 9, 2012 · Viewed 26k times · Source

How can I use touchesBegan: withEvent: method in UITableViewController class?

UITableViewController is a subclass of UIViewController class. So why the method does not works in UITableViewController?

Answer

Steph Sharp picture Steph Sharp · Feb 20, 2013

I had a similar problem, and found a different approach that doesn't involve subclassing UITableView. Another way to do this is to add a gesture recognizer to the UITableViewController's view.

I put this code in the UITableViewController's viewDidLoad:

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[self.view addGestureRecognizer:tap];

And implemented the event handler:

- (void)handleTap:(UITapGestureRecognizer *)recognizer
{
    // your code goes here...
}

I know this solution doesnt use touchesBegan, but I found it was a simple solution to the same problem.