的UIScrollView在UITableViewCell中进行滚动
问题描述:
我加入到具有滚动视图一个UITableView,我在小区的代码单元是:的UIScrollView在UITableViewCell中进行滚动
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];
然而,这并不滚动:(如果我有一样的。在实现代码如下外部的代码段,这直接添加到视图,它按预期工作我缺少什么
答
尝试[细胞addSubview:滚动视图];
+0
上面的代码是在一个自定义的TableViewCell.m类中,所以[self addSubview:scrollView]实际上是添加到UITableViewCell实例 – user3570727 2014-11-14 18:31:21
答
尝试添加滚动视图到的UITableViewCell的内容查看和?也许设置
self.contentView.userInteractionEnabled = NO
从参考的UITableViewCell doc
讨论 一个UITableViewCell对象的内容视图是由该单元所显示的内容的缺省上海华。如果您想通过简单地添加附加视图来自定义单元格,则应该将它们添加到内容视图中,以便在单元格进入和退出编辑模式时适当定位它们。
你试过了吗[self.contentView addSubview:scrollView]; – Vig 2014-11-14 18:56:36
你是否得到这个工作? – DevC 2015-01-13 15:39:46