Note that there are some explanatory texts on larger screens.

plurals
  1. POGCD and cell reuse in UICollectionView
    primarykey
    data
    text
    <p>I have a <code>UICollectionView</code> implementation with a custom <code>UICollectionViewCell</code>. The array of data is fetched from the internet but the images are downloaded as the user is accessing the content. </p> <p>While this is probably not the most efficient way and I do not plan on leave it this way, it did expose a certain issue which I am struggling to solve. It seems that the cells are displaying "cached" or "old" images and as I slowly scroll the collection view, the cell images keep on changing.</p> <p>This is probably an issue with the actual cell image not being available from the net at that moment in time and my question is how do I force an empty cell or some loading activitity monitor and not displaying an incorrect image?</p> <p>Thanks in advance, pinion</p> <pre><code>-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString * CellIdentifier = @"Event"; EventCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; NSString *title = [[events objectAtIndex:indexPath.item] objectForKey:@"title"]; NSString *imageUrl = [[[events objectAtIndex:indexPath.item] objectForKey:@"photo"] objectForKey:@"url"]; dispatch_queue_t imageFetchQ = dispatch_queue_create("image fetched", NULL); dispatch_async(imageFetchQ, ^{ NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]; if (imageData) { dispatch_async(dispatch_get_main_queue(), ^{ cell.eventImage.image = [UIImage imageWithData:imageData]; cell.eventTitle.text = title; }); } }); return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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