And*_*xko 6 ios uicollectionview uicollectionviewcell
我用a UICollectionview来显示很多自定义单元格(250或更少).
那些单元格有一个主图像和一些文本.由于图像必须从Internet下载,我使用外部库AsyncImageView来执行延迟加载.
但问题是细胞的可重复使用性能让我发疯.
当我滚动图像出现在错误的单元格中时.除了索引路径之外,如何向图像添加标记或其他内容以避免出现问题?
也许AsyncImageView有一个我忽略的问题的解决方案......
或者另一种选择是更好的选择?
任何线索?
提前致谢
编辑:我的代码的简化版本
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
CollectionComercioCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
if (cell == nil){
}
else{
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget: cell.myImage];
}
cell.myImage.imageURL = nil;
cell.myImage.image = nil;
cell.myImage.hidden = TRUE;
cell.myImage.imageURL = [[myArray objectAtIndex:indexPath.row] getLogoUrl];
cell.myText.text = [[myArray objectAtIndex:indexPath.row] getName];
cell.myImage.hidden = FALSE;
return cell;
Run Code Online (Sandbox Code Playgroud)
}
CustomCell.m
- (void)prepareForReuse
{
[super prepareForReuse];
self.myImage.image = nil;
}
Run Code Online (Sandbox Code Playgroud)
确保在cellForRowAtIndexPath:方法中将图像设置为nil .这样它将保持至少为空,直到加载新图像.
正如您在评论中提到的那样,如果您滚动速度慢,而不是滚动速度快,则可以覆盖- (void)prepareForReuse自定义单元格.但请注意,Apple警告您不要将其用于内容更改:
出于性能原因,您应该仅重置与内容无关的单元格属性,例如,alpha,编辑和选择状态.tableView中的表视图委托:cellForRowAtIndexPath:在重用单元格时应始终重置所有内容.如果单元对象没有关联的重用标识符,则不会调用此方法.如果重写此方法,则必须确保调用超类实现.
| 归档时间: |
|
| 查看次数: |
2161 次 |
| 最近记录: |