当我们滚动tableview然后表中的图像更改和覆盖,如何管理?

时间:2016-02-21 07:10:57

标签: ios objective-c uitableview

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *cellIdentifier= @"Identifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    UIImageView *typeImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 15, 15)];
    [cell addSubview:typeImageView];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    if (indexPath.section == 0) {

    }
    else if (indexPath.section == 1) {
         typeImageView.image = [UIImage imageNamed:[imageArray objectAtIndex:indexPath.row]];
    }
    return cell;
}

这里第0部分不包含imageview,但是当我们滚动时,然后在第0部分中添加了图像。每次,当我们滚动tableview图像覆盖到前一个时。

1 个答案:

答案 0 :(得分:0)

这是一个单元格出列问题。尝试在0部分图像视图中设置nil。 您还要将图像视图添加为所有单元格的子视图。这将解决问题。添加子视图时检查子视图是否已存在。 我希望这很有用。