Xcode SDWebImage和UITableViewCell

Xcode SDWebImage和UITableViewCell,xcode,cocoa-touch,uitableview,sdwebimage,Xcode,Cocoa Touch,Uitableview,Sdwebimage,我正在使用SDWebImage和UITableView - (UITableViewCell *)tableView:(UITableView *)the_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier"]; NSDictionary *info = [tableData obj

我正在使用SDWebImage和UITableView

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

    NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier"];
    NSDictionary *info = [tableData objectAtIndex:indexPath.row];

    UITableViewCell *cell = [the_tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] autorelease];
        if(!addImage) [addImage release];
        addImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder.png"]];
        [addImage setFrame:CGRectMake(7, 10, 50, 50)];
        [cell setIndentationLevel:6];
        [cell.contentView addSubview:addImage];
    }

    if(info !=  NULL) {
        cell.textLabel.text = [info objectForKey:@"title"];
        cell.detailTextLabel.text = [NSString stringWithFormat:@"Version: %@",[info objectForKey:@"version"]];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        NSString *imageURL = [NSString stringWithFormat:@"%@",[info objectForKey:@"imageURL"]];
        [addImage setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];         
    }
    return cell;
}
这对前6个结果非常有效(可以在即时视图中显示的数量)

但当我向下滚动列表时,它似乎只是重复使用前6个单元格中的图像,在某些单元格中,图像会根据它们在屏幕上的位置而变化

此外,如果我调用reloadData,则来自上一个UITableCell的图像将保留在屏幕上

我做错什么了吗?我遵循了github上的示例代码

谢谢

(由OP在问题编辑中回答。作为社区wiki答案移至此处。请参阅)

OP写道:

好的,我发现了问题

对于其他有同样问题的人来说,这就是你做错的地方

请注意,在创建单元格时,我是如何将图像添加到子视图的:

嗯,
SDWebImage
试图做的是不断更新
addImage
变量,它不是我的cell类的属性

所以,我解决这个问题的方法是创建我自己的
UITableViewCell
子类,init带有
ImageView
,我在该属性上获得
SDWebImage
setImage

我希望这对别人有帮助

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] autorelease];
addImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder.png"]];
[addImage setFrame:CGRectMake(7, 10, 50, 50)];
[cell.contentView addSubview:addImage];