UITableViewCell 中的 UIScrollView 不滚动

2024-04-18

我正在向具有滚动视图的 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];

然而,这不会滚动:(。如果我在表视图之外有相同的代码段并将其直接添加到视图中,它会按预期工作。我错过了什么?


尝试 [cell addSubview:scrollView];

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

UITableViewCell 中的 UIScrollView 不滚动 的相关文章

随机推荐