UITableView在滚动时重叠

ron*_*yrr 0 scroll objective-c uitableview overlapping

在我的故事板中,我有一个表格视图.我正在使用从JSON文件加载的数据(在viewDidLoad中加载)填充该表视图.

在我的UITableView中,我确实将"Prototype Cells"设置为1,因此我可以轻松选择附件.我的Prototype Cell有一个Seque到一个新视图,需要显示所选项目的详细信息.

我用以下方式以编程方式填充我的单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *videoTableIdentifier = @"VideoCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:videoTableIdentifier];

    if (cell == nil)
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:videoTableIdentifier];

    UILabel * title = [[UILabel alloc] initWithFrame:CGRectMake(40,5, 240,20)];
    [cell addSubview:title];
    [title setText:[[videos objectAtIndex:indexPath.row] objectForKey:@"title"]];

    UILabel * detail = [[UILabel alloc] initWithFrame:CGRectMake(40,28, 100,10)];
    [cell addSubview:detail];
    [detail setText:[NSString stringWithFormat:@"Year: %@", [[videos objectAtIndex:indexPath.row] objectForKey:@"year"]]];

    [cell addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:[[videos objectAtIndex:indexPath.row] objectForKey:@"image"]]]];

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

当我开始滚动时,会发生以下情况: 在此输入图像描述

所以我开始寻找解决方案,发现我必须设置:dequeueReusableCellWithIdentifier:videoTableIdentifier"nil".

虽然我这样做了,但这解决了我的问题,现在我的Prototype Cell Accessory和Seque已经不见了,所以我再也无法导航到下一个视图了.

我无法在互联网上找到解决方案,所以我决定问这个问题.如果有人可以提供帮助,那会很棒.

Ant*_* MG 6

您的问题是,每次重新使用单元格时,都会向其中添加新的子视图,因此如果您有一个带有某些标签的单元格,并且重复使用它并添加更多标签,则所有这些标签都会重叠.

我建议你自己制作带有标签的自定义UITableViewCell,每次只更改标签的值.