[英]How to different cell size for all the cells in UIcollectionView
[英]How to update size of cells in UICollectionView after cell data is set?
所以我有一个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]];
}
没有答案,但我没有足够的声誉来发表评论。
我试图更新我的collectionviewcell,我把图像加载到下面:
[self.delegate imageReadyForCell:cell]
但这并没有改变任何东西,我在imageReadyForCell方法中放置了断点,但它甚至没有达到它。 我按照上面完成的所有步骤操作,并使用了CellDelegate的委托人的协议和属性,但我没有设法使该工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.