0
我使用UICollectionView
与自动布局显示画廊。我有两种类型的prototype cells
- 一个用于显示2列colourView和一个用于3-columned视图。UICollectionView汽车的布局,不同的细胞
在按一下按钮,在视图被切换到2圆柱和三圆柱
以下是我的代码:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellGrid" forIndexPath:indexPath];
if([selected_layout isEqualToString:@"tile"]){
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellTile" forIndexPath:indexPath]; // for 2 columns
} else {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellGrid" forIndexPath:indexPath]; // for 3 columns
}
[cell layoutIfNeeded];
[cell setNeedsDisplay];
return cell;
}
我不设置单元格的高度/宽度在代码的任何地方,我刚刚在xib中指定了它。但是每次显示3个圆柱状的collectionView
时,每个单元之间的黑色间隙大约为10个像素。
我提到this link,但它是用快速和自定义单元格类。我不想使用它。
我该如何解决这个问题?我哪里错了?
如果单元格大小不同的方式,你需要在收藏品视图,设置单元格大小, - (CGSize)的CollectionView:(UICollectionView *)的CollectionView 布局:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section if([selected_layout isEqualToString:@“tile”]) return CGSizeMake(collectionView.frame.size.width/3,50); else return CGSizeMake(collectionView.frame.size.width/2,50); }这样的 – NANNAV
@NANNAV试过了,还是一样的。为什么我需要设置页脚大小? 'referenceSizeForFooterInSection' – z22
您是否每次检查selected_layout值? – sourav