UIScrollView inside UITableViewCell - No didSelect call

I have tableviewCellwhere the user can scrollhorizontally. Since it scrollViewcovers almost everything cell, the method is tableView didSelectRownot called if the user clicks a button cell.

So, I thought that I could pass the touch event UIScrollViewto cell, but still the call was didSelectRownot called. I subclassed UIScrollViewto pass a touch event only if the touch was not a drag:

- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
{
    NSLog(@"touch scroll");
    // If not dragging, send event to next responder
    if (!self.dragging)
        [self.superview touchesEnded: touches withEvent:event];
    else
        [super touchesEnded: touches withEvent: event];
}

Any ideas on how to pass a click into a table to trigger delegate calls and keep scrolling inside scrollView?

+5
source share
5 answers

UIScrollView. cellForRowAtIndexPath UITableView, :

[cell.contentView addSubview:yourScrollView];
yourScrollView.userInteractionEnabled = NO;
[cell.contentView addGestureRecognizer:yourScrollView.panGestureRecognizer];

, , , scrollView panGestureRecognizer, . , scrollview.

, - . , .

+11

.
:

-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    if (!self.dragging)
        [self.superview touchesCancelled: touches withEvent:event];
    else
        [super touchesCancelled: touches withEvent: event];
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    if (!self.dragging)
        [self.superview touchesMoved: touches withEvent:event];
    else
        [super touchesMoved: touches withEvent: event];
}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if (!self.dragging)
        [self.superview touchesBegan: touches withEvent:event];
    else
        [super touchesBegan: touches withEvent: event];
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if (!self.dragging)
        [self.superview touchesEnded: touches withEvent:event];
    else
        [super touchesEnded: touches withEvent: event];
}
+7

_scrollView.canCancelContentTouches = NO

0

, , .

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.dragging) {
        [super touchesMoved:touches withEvent:event];
    } else {
        if ([self.delegate isKindOfClass:[UITableViewCell class]]) {
            [(UITableViewCell *)self.delegate touchesCancelled:touches withEvent:event];
        }

        [self.superview touchesMoved:touches withEvent:event];
    }
}

self.delegate UITableViewCell, .

, . .

  • ( , )
  • ,
  • , didSelectCell

, , - ! self.delegate self.superview, .

0

Swift 3

scrollView.isUserInteractionEnabled = false
contentView.addGestureRecognizer(scrollView.panGestureRecognizer)
0

All Articles