Why does my UITableView not respond to touchesBegan?

后端 未结 3 952
-上瘾入骨i
-上瘾入骨i 2021-01-21 18:22

I am using this method

- (void)tableView:(UITableView *)tableView touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTou         


        
3条回答
  •  迷失自我
    2021-01-21 18:56

    Here is a UITableView subclass solution that worked for me. Make a subclass of UITableView and override hitTest:withEvent: as below:

    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    
        static UIEvent *e = nil;
    
        if (e != nil && e == event) {
            e = nil;
            return [super hitTest:point withEvent:event];
        }
    
        e = event;
    
        if (event.type == UIEventTypeTouches) {
            NSSet *touches = [event touchesForView:self];
            UITouch *touch = [touches anyObject];
            if (touch.phase == UITouchPhaseBegan) {
                NSLog(@"Touches began");
            }
        }
        return [super hitTest:point withEvent:event];
    }
    

提交回复
热议问题