gpt4 book ai didi

ios - 闪烁图像 tableview 重用错误请参阅视频链接 -->http ://www. youtube.com/watch?v=jwEsqjc9sNc&feature=youtu.be

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:22:10 28 4
gpt4 key购买 nike

代码如下:我在后台从我的核心数据下载图像并将其放在我的 ImageView 中。

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;

有什么解决办法吗?提前致谢。

最佳答案

在开始异步加载任务之前,您需要将图像设置为 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];
});
});

这是因为加载图像需要一些时间,所以您会看到旧图像,因为表格单元格在可用时会被重用。

关于ios - 闪烁图像 tableview 重用错误请参阅视频链接 -->http ://www. youtube.com/watch?v=jwEsqjc9sNc&feature=youtu.be,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22337178/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com