I'm using NINetworkImageView from Nimbuskit. I have a simple UICollectionView showing a grid of images (NINetworkImageViews). Normally it works like a charm, but in certain situations some of the NINetworkImageViews show a wrong image.
I think it happens when there is no path for the image and NINetworkImageView has to show the default image. Sometimes (few times) instead of showing the default image, it appears other image belonging to other NINetworkImageView of the CollectionView.
Here is the related code:
- (UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"ShelvingCell";
ShelvingCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
// Prueba para ver si esto arregla lo de que se repitan imágenes
[cell.feedNetworkImageView prepareForReuse];
cell.feedNetworkImageView.delegate = self;
// El collage necesita un tratamiento especial
if (indexPath.section == 0 && indexPath.row == 0)
{
cell.feedTitleLabel.text = @"";
cell.lastFeedNewTitleLabel.text = @"";
// Prueba para ver si esto arregla lo de que se repitan imágenes
[cell.feedNetworkImageView setPathToNetworkImage:@""];
// Prueba para ver si esto arregla lo de que se repitan imágenes
[cell.feedNetworkImageView prepareForReuse];
cell.feedNetworkImageView.image = [UIImage imageNamed:@"collage.png"];
}
else
{
MOFeed *feed = [self.feeds objectAtIndex:(indexPath.section*3 + indexPath.row - 1)];
cell.feedTitleLabel.text = feed.title;
// Recuperamos la última noticia del feed
MONoticia *ultimaNoticia = [feed lastFeedNew];
cell.lastFeedNewTitleLabel.text = ultimaNoticia.title;
if (![feed.feedImageURL isEqualToString:@""] && feed.feedImageURL)
{
// Prueba para ver si esto arregla lo de que se repitan imágenes
[cell.feedNetworkImageView prepareForReuse];
[cell.feedNetworkImageView setPathToNetworkImage:feed.feedImageURL];
}
else
{
// Prueba para ver si esto arregla lo de que se repitan imágenes
[cell.feedNetworkImageView prepareForReuse];
cell.feedNetworkImageView.image = [UIImage imageNamed:@"shelvingcell.png"];
// Prueba para ver si esto arregla lo de que se repitan imágenes
[cell.feedNetworkImageView setPathToNetworkImage:@""];
}
}
return cell;
}
Thanks a lot!
Carlos