Touches began in UITableViewController

后端 未结 5 1915
长发绾君心
长发绾君心 2021-01-17 22:38

I am defining this method in my UITableViewController subclass:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:to         


        
5条回答
  •  情话喂你
    2021-01-17 22:56

    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 
    
    @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
    

提交回复
热议问题