UITableViewCell中的UIScrollView不滚动

我正在向具有滚动视图的UITableView添加一个单元格,我在单元格中的代码是:

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30, 320, 44)]; UIView *labelView = [[UIView alloc] initWithFrame:CGRectMake(4, 4, 80 * _labels.count, 44)]; for (NSUInteger i = 0; i < _labels.count; i++) { NSString *aLabel = [_labels objectAtIndex:i]; UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(i * 70, 3, 60, 30)]; button.tag = i; [button setTitle:aLabel forState:UIControlStateNormal]; [button setBackgroundColor:[UIColor lightGrayColor]]; [labelView addSubview:button]; } scrollView.contentSize = CGSizeMake(labelView.frame.size.width, labelView.frame.size.height); [scrollView addSubview:labelView]; [self addSubview:scrollView]; 

但是这不会滚动:(。如果我在tableview之外有相同的代码段并将其直接添加到视图中,它会按预期工作。我缺少什么?

试试[cell addSubview:scrollView];

尝试将scrollView添加到UITableViewCell的contentView并进行设置

 self.contentView.userInteractionEnabled = NO 

来自UITableViewCell参考文档

讨论UITableViewCell对象的内容视图是单元格显示的内容的默认超级视图。 如果要通过简单地添加其他视图来自定义单元格,则应将它们添加到内容视图中,以便在单元格进入和退出编辑模式时将它们正确定位。