【发布时间】:2014-11-26 15:33:43
【问题描述】:
当我调用以下委托方法时:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
float cellWidth = 90.0f; float cellHeight = 60.0f;
int cellType = [[collectionView cellForItemAtIndexPath:indexPath] tag];
return CGSizeMake(cellWidth, cellHeight);
}
cellType 返回 0。 [collectionView cellForItemAtIndexPath:] 也返回 nil
我猜这是因为单元格没有调整大小,所以不显示,不显示时返回 nil(即在创建单元格对象的实例之前调用此方法)。
有没有办法获取在 collectionView:cellForItemAtIndexPath 方法中为此项目设置的信息?如何在 sizeForItemAtIndexPath 方法中识别单个单元格类型?
(我打算使用数据源 NSArray,但我试图将这个逻辑保留在显示对象中,而不是由数据管理。)
【问题讨论】:
-
我也在为此苦苦挣扎。我想获得每个可见单元格的大小,因为我的单元格会根据它们的内容改变大小。据我所知,[collectionView visibleCells] 和collectionView cellForItemAtIndexPath 都只在collectionView 可见时返回值——并且当调用此委托方法时,CV 不可见。
标签: ios xcode collectionview