sumderungHAY sumderungHAY - 1 year ago 158
Objective-C Question

Touches began in UITableViewController

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?

Answer Source

Yep, that should definitely work.

Make sure User Interaction Enabled is set for the view this controller corresponds to.

If the view is loaded from a nib/xib, make sure File's Owner is set to be the appropriate class name, and File's Owner's view outlet is connected to proper the view.

Update: I see this behavior as well, using an app built with the Nav-based App template, but with a View-based App template, it works as expected.

I think that in the case of a Navigation Controller, the table view embedded in the view controller is getting the event before the view controller does. See the UIView reference (emphasis mine):

View controllers are themselves descendants of the UIResponder class and are inserted into the responder chain between the managed root view and its superview, which typically belongs to a different view controller. If the view controller’s view does not handle an event, the view controller itself has the option of handling the event before passing the event along to the superview.

This implies that the view has the first chance to handle the event, and if it does, the view controller won't get it.

Not exactly clear what you're trying to accomplish, so I'm not sure what solution to offer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download