0

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?

Kampai
  • 22,848
  • 21
  • 95
  • 95
Xcobe
  • 111
  • 2
  • 7

1 Answers1

0

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.
}
Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
  • Thanks, it solved part of my problem, the new related problem is, I want the cell perform as a formal cell, means when touch the cell and hold the finger, the cell show "SELECTED" effect, but click event only be actived when finger touch up. Do you have any suggestion for this? – Xcobe Aug 01 '14 at 02:08
  • Just implement another gesture recognizer that would detect touch down event. Then, set the selected state of the cell when the event occurs. See this answer for info how to implement gesture recognizer http://stackoverflow.com/q/15628133/348796 – Rafał Sroka Aug 01 '14 at 07:04