UITcrollView在UITableViewCell内部 - 没有didSelect调用

Gri*_*arn 5 objective-c uikit ios

我有一个tableviewCell,用户可以scroll水平.由于scrollView覆盖几乎整个cell,如果用户点击该tableView方法didSelectRow,则不会调用该方法cell.

所以我想,我可以将触摸事件传递UIScrollViewcell,但仍然didSelectRow没有被调用.我UIScrollView只是传递触摸事件,如果触摸不是拖动:

- (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];
}
Run Code Online (Sandbox Code Playgroud)

有关如何将点击传递给表,获取委托方法调用并保持滚动内部的任何想法scrollview

cph*_*117 16

实际上,你可以做到这一点没有子UIScrollView.无论你是否有一个自定义单元格,或为其设置属性cellForRowAtIndexPathUITableView,你可以做到以下几点:

[cell.contentView addSubview:yourScrollView];
yourScrollView.userInteractionEnabled = NO;
[cell.contentView addGestureRecognizer:yourScrollView.panGestureRecognizer];
Run Code Online (Sandbox Code Playgroud)

你可以这样做的原因是因为scrollView有自己的panGestureRecognizer,程序员可以访问它.因此,只需将其添加到单元格的视图中,就会触发scrollview的手势委托.

这种方法的唯一缺点是滚动视图的子视图无法接收任何触摸输入.如果您需要这个,您将不得不选择不同的方法.


小智 7

我刚遇到同样的问题.
在您的子类中,请确保包含完整的方法集:

-(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];
}
Run Code Online (Sandbox Code Playgroud)


Bry*_*hen -1

尝试设置这个

_scrollView.canCancelContentTouches = NO
Run Code Online (Sandbox Code Playgroud)

另外,部分转发触摸事件也是不好的