为什么,当我创建一个CollectionView,并将两个具有不同标识符的单元格出现后,后者相互连接? 具有相同标识符的单元在它们之间具有相等的距离,而是具有不同标识符的单元被粘在一起。 这是我的代码:
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 2;
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
if (section == 0) {
return 1;
}
if (section == 1) {
return 10;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
UICollectionViewCell *cell;
if (indexPath.section == 0) {
cell = [cv dequeueReusableCellWithReuseIdentifier:@"AddCell" forIndexPath:indexPath];
UIImageView *cellImage = (UIImageView *)[cell viewWithTag:1];
[cellImage setImage:[UIImage imageNamed:@"pulsante_trasparente.png"]];
}
else if (indexPath.section == 1){
cell = [cv dequeueReusableCellWithReuseIdentifier:@"PictureCell" forIndexPath:indexPath];
UIImageView *cellImage = (UIImageView*)[cell viewWithTag:1];
[cellImage setImage:[UIImage imageNamed:@"mi.png"]];
}
return cell;
}
请帮助我!
答案 0 :(得分:1)
实现此方法以获取不同部分的单元格之间的空间:
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;
{
return UIEdgeInsetsMake(Top_Gap, Left_Gap, Buttom_Gap, Right_Gap);
}
答案 1 :(得分:0)
您是否尝试将单元格的最小间距设置为负值(如果不是这样),方法是转到xib中的UICollectionView
并选择检查器并自定义那里的最小空间。我有一张图片展示了我的意思: