Question

I have a custom table view cell that handles user gestures. However, even if I have exclusiveTouch set to YES, the moment the y value changes by any amount, scolling starts, even if I'm in the middle of handling the touch events. How do I prevent the table from scrolling when I'm handling touch events in the cell?

Was it helpful?

Solution

So, the correct way to conditionally handle unfortunately depends on the superView. For some view and events (like UITableView select), you need to forward the touchesBegan: event to nextResponder, keep track of your gesture, forward touchesMoved: events to the nextResponder until you detect your gesture, and when it's triggered you send a touchesCancelled: to the nextResponder, and hide all other events from the next responder (touchesEnded: and touchesCancelled:) until you receive touchesEnded: or touchesCancelled: yourself.

In a UIScrollView, however, there is the special case in that it doesn't depend on being the nextResponder to handle scroll events (Scrolling is most likely detected in methods like hitTest:). So no matter what you do with regards to forwarding or events or not, scrolling still happens. The only way to prevent scrolling from happen is to disable scrolling on the parent view as soon as your gesture is detected, and then re-enable scrolling when it ends or is cancelled.

OTHER TIPS

I think you need to subclass UITableView and implement hitTest:withEvent: This is how I did it for a custom cell I built to do left and right sliding within the cell:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    NSIndexPath *indexPath = [self indexPathForRowAtPoint:point];
    UITableViewCell *cell = [self cellForRowAtIndexPath:indexPath];

    if ([cell isKindOfClass:[MyCustomCell class]])
    {
        return cell;
    }

    return [super hitTest:point withEvent:event];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top