사용자 정의 셀이있는 UITableView가 있습니다. Grand Central Dispatch를 사용하여 이미지를 비동기 적으로로드합니다. 모든 것이 잘 작동하지만 아래로 스크롤하면 이전에로드 된 이미지가 새 이미지가 다운로드 될 때까지 표시됩니다.GCD UITableView 비동기로드 이미지, 새 이미지 다운로드까지 잘못된 셀로드 됨
if (![[NSFileManager defaultManager] fileExistsAtPath:[path stringByAppendingPathComponent:@"image.png"]])
{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSString *url=[pat stringByAppendingPathComponent:@"comments.txt"];
NSString *u=[NSString stringWithContentsOfFile:url encoding:NSUTF8StringEncoding error:nil];
NSURL *imageURL=[NSURL URLWithString:u];
NSData *image=[NSData dataWithContentsOfURL:imageURL];
[image writeToFile:[pat stringByAppendingPathComponent:@"image.png"] atomically:YES];
dispatch_sync(dispatch_get_main_queue(), ^{
cell.imageView.image=[UIImage imageWithContentsOfFile:[pat stringByAppendingPathComponent:@"image.png"]];
[cell setNeedsLayout];
NSLog(@"Download");
});
});
}
else
{
NSLog(@"cache");
cell.imageView.image=[UIImage imageWithContentsOfFile:[pat stringByAppendingPathComponent:@"image.png"]];
}
어떤 제안 평가 : 여기 내 코드입니다. 오후 8시 30 분 P.S. 셀을 다시 사용합니다.
답장을 보내 주셔서 감사합니다.하지만 몇 가지 예제 코드를 제공해 주시겠습니까? – blackhawk4152
내 대답이 업데이트되었습니다 – hypercrypt
감사합니다. 그냥 내가 원했던 것 – blackhawk4152