Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableViewCell load images and reused cells
    primarykey
    data
    text
    <p>i need to load from web/files some UIImages. I was searching and i found in other <a href="https://stackoverflow.com/questions/7852033/gcd-uitableview-asynchronous-load-images-wrong-cells-are-loaded-until-new-image">question</a> this code:</p> <pre><code> if (![[NSFileManager defaultManager] fileExistsAtPath:user.image]) { dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); dispatch_async(queue, ^{ NSData *imageData =[NSData dataWithContentsOfURL:[NSURL URLWithString:user.imageURL]]; [imageData writeToFile:user.image atomically:YES]; dispatch_sync(dispatch_get_main_queue(), ^{ UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; UIImage *image = [UIImage imageWithData:imageData]; [self.imageFriends setObject:image forKey:[NSNumber numberWithInt:user.userId]]; cell.imageView.image = image; [cell setNeedsLayout]; NSLog(@"Download %@",user.image); }); }); cell.imageView.image=[UIImage imageNamed:@"xger86x.jpg"]; } else { NSLog(@"cache"); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); dispatch_async(queue, ^{ UIImage *image = [UIImage imageWithContentsOfFile:user.image]; //[self.imageFriends setObject:image forKey:[NSNumber numberWithInt:user.userId]]; dispatch_sync(dispatch_get_main_queue(), ^{ UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath]; newCell.imageView.image=image; [newCell setNeedsLayout]; }); }); } </code></pre> <p>But the problem is that when i scroll fast to bottom or top the images are loaded wrong and there is a short lag when it ends. </p> <p>So the question is.. how can i load the UIImages in the correct cell when i use queues to fetch them? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload