我有一个根据上一个中UICollectionview
的结果加载的。在集合的单元格中,我从互联网加载图像。当被调用时,我在单元格的图像上放置一个占位符,然后开始从 Internet 下载图像。下载完成后,我重新加载单元格,以便正确放置最终图像。因此,每个单元格调用该方法两次。serchbar
UIViewController
collectionView:(UICollectionView *)cv cellForItemAtIndexPath:
这是可能感兴趣的代码部分:
- (TXCeldaPOICollection *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
TXCeldaPOICollection *cell = [cv dequeueReusableCellWithReuseIdentifier:@"CeldaPOI" forIndexPath:indexPath];
...
NSNumber *estaDisponible=[disponibles objectAtIndex:indexPath.row];
if ([estaDisponible boolValue]==YES) {
cell.imgCelda.image=[imagenes objectAtIndex:indexPath.row];
NSLog(@"Imagen disponible en la celda numero numero %ld",(long)indexPath.row);
} else {
cell.imgCelda.image=[UIImage imageNamed:@"placeholder.png"];
NSLog(@"Placeholder colocado en la celda numero numero %ld",(long)indexPath.row);
// Monto la URL de descarga:
NSString *urlDescarga=kBaseURL;
urlDescarga=[urlDescarga stringByAppendingString:[[self.listaCeldas objectAtIndex:indexPath.row] valueForKey:@"foto1"]];
NSURL *direccion=[NSURL URLWithString:urlDescarga];
[self downloadImageWithURL:direccion conOrden:self.estadioFiltrado completionBlock:^(BOOL succeeded, UIImage *image, NSInteger ordenacion) {
if (succeeded) {
NSLog(@"Imagen descargada estadio %ld orden %ld indice %ld poi %ld@",self.estadioFiltrado, ordenacion, indexPath.row, [seleccionado.identificador integerValue]);
if (ordenacion==self.estadioFiltrado) {
if (image!=nil) {
//Meto comprobacion de no rebase del array aunque genere algun error me protejo frente a cueelgues
NSInteger numeroImagenes= imagenes.count;
if (indexPath.row<=numeroImagenes-1) {
[imagenes replaceObjectAtIndex:indexPath.row withObject:image];
[disponibles replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithBool:YES]];
NSArray *recargar=[[NSArray alloc] initWithObjects:indexPath, nil];
NSLog(@"Imagen DESCARGADA numero %ld y llamando a recargar ccelda",(long)indexPath.row);
[self.coleccion reloadItemsAtIndexPaths:recargar];
}
}
}
} else {
}
}];
}
}
现在奇怪的事情来了。当我第一次在前一个搜索栏中为特定搜索加载 collectionview 时,行为是预期的。每个单元格被调用两次,我可以在短时间内看到单元格中的占位符,然后出现不同的图像。所以一切正常。
但是,如果我从显示集合视图的那个返回到搜索栏-popViewController
-如果我再次加载相同的集合视图会发生一些奇怪的事情-选择的搜索栏的结果相同-。首先我可以看到旧单元格 - 我知道它们是旧单元格,因为没有调用新单元格的方法 - 然后我看到占位符,最终看到与旧单元格相同的最终图像,但效果不好,因为你看到了:image-placeholder-image。
问题是定义单元格的方法只为每个单元格调用两次,这是应该的,但显示了单元格的初始内容。
我已经阅读了一些类似的问题,并且我尝试了两种方法但没有成功: - 我已经Prepareforreuse
在我的单元类中实现了该方法。- 我用过这个-(void)collectionView:(UICollectionView *)cv didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
方法。
正如我所说,没有结果。还有什么想法吗?我已经解决这个问题两天了,我真的很绝望。