UITableViewCell中的UIScrollView无法滚动 [英] UIScrollView in UITableViewCell not scrolling
本文介绍了UITableViewCell中的UIScrollView无法滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将一个单元格添加到具有滚动视图的UITableView中,该单元格中的代码是:
I am adding a cell to a UITableView which has a scrollview, the code I have in the cell is :
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外有相同的代码段,并将其直接添加到视图中,它将按预期工作.我缺少什么?
However this does not scroll :(. If I have the same code segment outside the tableview and add this directly to the view, it works as expected. What am I missing?
推荐答案
尝试将scrollView添加到UITableViewCell的contentView中,然后进行设置
Try adding the scrollView to the contentView of the UITableViewCell and maybe setting
self.contentView.userInteractionEnabled = NO
从UITableViewCell参考文档
From the UITableViewCell reference doc
讨论UITableViewCell对象的内容视图是单元格显示的内容的默认超级视图.如果您只想通过添加其他视图来自定义单元格,则应将其添加到内容视图中,以便在单元格进入和退出编辑模式时可以适当地放置它们.
这篇关于UITableViewCell中的UIScrollView无法滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文