I have a collection view and for some cells I want to return a specific height, and some others, I want to fall back to automatic size. Here is my code:
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if(something){
return UICollectionViewFlowLayoutAutomaticSize;
}else{
return some CGSize
}
}
However, I get EXC_BAD_ACCESS error when I try to return UICollectionViewFlowLayoutAutomaticSize
. I've also tried to set the size to automatic dimension on flow layout itself:
UICollectionViewFlowLayout* layout = (UICollectionViewFlowLayout*)self.collectionViewLayout;
layout.itemSize = UICollectionViewFlowLayoutAutomaticSize;
I'm also getting the same error when I assign to UICollectionViewFlowLayoutAutomaticSize
either.
What am I doing wrong?
答案 0 :(得分:1)
不确定这是否与您的问题有关,但我还有一个EXC_BAD_ACCESS
,其中包含一个带有流程布局的集合视图。结果更改.estimatedItemSize
修复了问题:
let flowLayout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
// this breaks
flowLayout.estimatedItemSize = CGSize(width: 100, height: 100)
// this does not break
flowLayout.estimatedItemSize = CGSize(width: 1, height: 1)
我的细胞只有一个标签,所以它们小于100x100。我想如果你给出的估计尺寸大于实际尺寸就不好......
希望这有助于任何人。