Rameez Hussain Rameez Hussain - 1 year ago 87
iOS Question

UICollectionView repeats cell

I have a

where I display a grid of images downloaded from the Internet. I am using
to load the images. The problem I am facing is that, when I scroll through the
, sometimes the cells repeat themselves, displaying the same image. But when the cell is scroll out of view and then brought back, it has the right image set.

-(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

NSString *CellIdentifier = @"Gallery_Cell";

GalleryCell *cell;

if (cell==nil) {
cell= (GalleryCell *)[self.flowCollection dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

ImageItem *dets = [self.imageList objectAtIndex:indexPath.row];

NSURL *mainImageURL = [NSURL URLWithString:dets.smallImageURL];

cell.image.contentMode = UIViewContentModeScaleAspectFill;
cell.image.clipsToBounds = YES;

[cell.image setImageWithURL:mainImageURL placeholderImage:nil];


return cell;


Has this happened to anyone else? Would highly appreciate any pointers.

Answer Source

I ended up using “didEndDisplayingCell” method of UICollectionView and ending the current Image download and setting the image to nil. This worked perfectly and there was no more “shuffling” or repetition of images! :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download