UITcrollView在UITableViewCell内部 - 没有didSelect调用 [英] UIScrollView inside a UITableViewCell - No didSelect call

查看:80
本文介绍了UITcrollView在UITableViewCell内部 - 没有didSelect调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 tableviewCell ,其中用户可以水平滚动。由于 scrollView 几乎涵盖整个单元格 tableView 如果用户单击单元格,则不会调用 didSelectRow 方法。

I have a tableviewCell, where the user can scroll horizontally. Since the scrollView covers nearly the whole cell, the tableView method didSelectRow gets not called if the user clicks the cell.

所以我想,我可以将 UIScrollView 的触摸事件传递给单元格,但仍然是 didSelectRow 没有被调用。
我将 UIScrollView 子类化为仅传递触摸事件,如果触摸不是拖动:

So I thought, I could pass the touch event of the UIScrollView to the cell, but still the didSelectRow doesnt gets called. I subclassed UIScrollView to pass the 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];
}

有关如何将点击传递到表格以获取代表的任何想法-methods调用并保持滚动 scrollview

Any ideas on how to pass the click to the table, to get the delegate-methods called and keep the scrolling inside the scrollview?

推荐答案

你实际上可以在没有继承 UIScrollView 的情况下执行此操作。无论您是自定义单元格,还是在 UITableView 中的 cellForRowAtIndexPath 中设置属性,您都可以执行以下操作: / p>

You can actually do this without subclassing UIScrollView. Whether you have a custom cell, or are setting properties in cellForRowAtIndexPath in the UITableView, you can do the following:

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

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

The reason you can do this is because scrollView has its own panGestureRecognizer that's accessible to the programmer. So, just adding it to the cell's view will trigger the scrollview's gesture delegates.

此方法的唯一缺点是滚动视图的子视图无法接收任何触摸输入。如果你需要这个,你必须选择不同的方法。

The only drawback of this approach is that subviews of the scroll view are unable to receive any touch input. If you need this you will have to chose a different approach.

这篇关于UITcrollView在UITableViewCell内部 - 没有didSelect调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆