问题描述:

I have a customized UITableViewCell, and in the cell, there is a UIScrollView, If I set User Interactive to True for UIScrollView, UIScrollView can work but the cell Click Event could not be handled, and if I set User Interactive to False for UIScrollView, cell can catch the Click event. Now I want to both UIScrollViewand cell click are handled, how to do that?

网友答案:

Add a tap gesture on UIScrollView.

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];

recognizer.umberOfTapsRequired = 1;
yourScrollView.userInteractionEnabled = YES;

[yourScrollView addGestureRecognizer:recognizer];

Add above code where you are setting up a cell. For example in cellForRowAtIndexPath: method. And handle the tap:

-(void)handleTapGesture:(UITapGestureRecognizer *)sender
{
    CGPoint location = [sender locationOfTouch:0 inView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchLocation];

    // Handle tap.
}
相关阅读:
Top