我正在为UICollectionView延迟加载图像。该图像正在显示,但是当我滚动UICollectionView时,图像会改变它们的位置,并且有重复的图像,所有图像都应该是唯一的。这里是我的代码:延迟加载的图像问题UICollectionView
- (gridcell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
gridcell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"gallerycollection" forIndexPath:indexPath];
NSDictionary *appsdict = [array_grid objectAtIndex:indexPath.item];
cell.image_grid.image=[UIImage imageNamed:@"griddummyloading"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSURL *imageURL = [NSURL URLWithString:[appsdict objectForKey:@"iosthumbnail"]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
cell.image_grid.image=image;
});
});
[collectionview_grid setAllowsSelection:YES];
return cell;
}
您是从单元格的'prepareForReuse'方法中删除单元格中的图像吗?如果没有,它可能会显示以前使用单元格的图像。 – bobnoble
我的代码我需要改变任何东西? – sures
您是否在uicollectionview中使用了多个部分? –