Alex Rivera | Logout

Touches began in UITableViewController

Asked 2011-06-08T22:53:20.513
9

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

Edit
Report

1 Answer

1

You need to pass the touches up the responder chain. We can do this by subclassing UITableView and overriding touchesBegan (and others if needed) and then passing the touches up the responder chain to the UITableViewController.

UITableViewTouch.h:

#import <UIKit/UIKit.h>

@interface UITableViewTouch : UITableView

@end

UITableViewTouch.m:

#import "UITableViewTouch.h"

@implementation UITableViewTouch

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [[self nextResponder] touchesBegan:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesCancelled:touches withEvent:event];
    [[self nextResponder] touchesCancelled:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
    [[self nextResponder] touchesEnded:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesMoved:touches withEvent:event];
    [[self nextResponder] touchesMoved:touches withEvent:event];
}

@end
answered 2012-12-28T23:05:08.030

Your Answer