我有一个包含不同自定义单元格的集合视图。
这些单元格包含大小不同的不同内容。
单元格在 Storyboard 中定义,因此无需在代码中注册。
我现在要做的就是根据内容更改委托方法中的大小:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
id cellAtIndexPath = [collectionView cellForItemAtIndexPath:indexPath];
NSLog(@"The cell: %@", cellAtIndexPath);
...
e.g. calling sizeToFit methods and cumulating the sizes of the cells' subviews
...
}
该方法按预期为每个单元格调用,但 cellAtIndexPath 始终返回 NULL,无论我尝试什么。所以我无法访问 indexPath 或其内容视图中的单元格对象。
有什么建议为什么我无法访问单元格对象?