闪烁图像tableview重用bug看到视频链接 - > http://www.youtube.com/watch?v=jwEsqjc9sNc&feature=youtu.be

l.v*_*lev 3 reusability tableview ios

这是代码:我正在从背景上的核心数据下载图像并将其放在我的图像视图中.

static NSString *cellIdentifier = @"Pubs Cell";
PubsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

Pub *current = [self.fetchController objectAtIndexPath:indexPath];

cell.name.text = current.name;
cell.description.text = current.descriptionText;
cell.description.backgroundColor = [UIColor clearColor];
cell.description.editable = NO;
dispatch_queue_t queue = dispatch_queue_create("image_queue", NULL);
dispatch_async(queue, ^{
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",current.photo]]];
    dispatch_async(dispatch_get_main_queue(), ^{

        cell.pubImage.image = [UIImage imageWithData:data];
    });
});
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"light1.jpg"]];

return cell;
Run Code Online (Sandbox Code Playgroud)

任何想法如何解决?提前致谢.

nil*_*ils 5

在启动异步加载任务之前,需要将映像设置为nil:

// removing the old image from the reused tablecell
cell.pubImage.image = nil;

// load image asynchronously
dispatch_queue_t queue = dispatch_queue_create("image_queue", NULL);
dispatch_async(queue, ^{
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",current.photo]]];
    dispatch_async(dispatch_get_main_queue(), ^{
        cell.pubImage.image = [UIImage imageWithData:data];
    });
});
Run Code Online (Sandbox Code Playgroud)

这是因为加载图像需要一些时间,因此您可以看到旧图像,因为可用时会重复使用tablecells.