所以我有一个UICollectionView在每个单元格中都有一个不同大小的不同图像。调用cellForItemAtIndexPath:时,我使用一种方法来更新UICollectionViewCell,该方法可在网络上异步获取图像并以完整尺寸显示它。
我的问题是我的单元格大小已经预先用sizeForItemAtIndexPath设置了。我希望它被召回,因此该单元具有下载的图像大小。
我怎样才能做到这一点?
如果已经设置好大小,请找到要刷新的单元格的索引:
NSIndexPath * indexPathOfCellToResize = // index path of cell to refresh
[myCollectionView reloadItemsAtIndexPaths:@[indexPathOfCellToResize]];
可能有更好的方法来执行此操作,但这是可行的:
在单元中创建代理协议
@protocol CellDelegate
- (void) imageIsReadyForCell:(id)cell;
@end
委托财产
@property (strong, nonatomic) id<CellDelegate>delegate;
在单元格中,当图像结束调用时:
[self.delegate imageIsReadyForCell:self];
然后在您的文件中托管collectionView接口
@interface SomeViewController : UIViewController <CellDelegate>
并在.m中
- (void) imageIsReadyForCell:(id)cell {
NSIndexPath * indexOfReadyCell = [yourCollectionView indexPathForCell:cell];
[myCollectionView reloadItemsAtIndexPaths:@[indexPathOfReadyCell]];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句