0
votes

For my needs I have a UITableView directly added under a UISCrollView :

--- Main UIView

-------- UITableView

-------- UIScrollView

So when I scroll my scrollview I change the content offset of my tableview. It works perfectly. But when I tried to select a cell I can't catch delegate method :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

Is there something special to do ? I tried to subclass UIScrollView and implement :

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

It works but I can't scroll my UIScrollView ...

1
It appears your scroll view is catching all the touch events, since its is covering the table view. - egghese
Yes it does that's why I would like to know if there is a way to transmit a touch event to the views under it ... - Pete
Probably you should forward all the tap events to the tableview and keep all the other touch events to uiscrollview, as of now you are for warding everything to table view via - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event. Though this can be implemented, review your logic. What you are doing is not proper. There will be another way to attain what you want. - egghese
Why do you have a scrollview over your tableview? Are you sure it needs to be there? - Fogmeister
This should answer your question: stackoverflow.com/questions/11480201/… - SIGKILL

1 Answers

2
votes

Try this,

-(void)handleSingleTap:(UILongPressGestureRecognizer *)gestureRecognizer{
    CGPoint p = [gestureRecognizer locationInView:myScroll];
    NSIndexPath *indexPath = [myTable indexPathForRowAtPoint:p];
    [myTable selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    [self tableView:myTable didSelectRowAtIndexPath:indexPath];
}

you have to use UITapGestureRecognizer...

UITapGestureRecognizer *tpgr = [[UITapGestureRecognizer alloc]
                                initWithTarget:self action:@selector(handleSingleTap:)];
tpgr.numberOfTapsRequired = 1;
[myScroll addGestureRecognizer:tpgr];