0

为什么,当我创建一个 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;
}

请帮我!

4

2 回答 2

2

实现此方法以获取不同部分的单元格之间的空间:

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;
{
    return UIEdgeInsetsMake(Top_Gap, Left_Gap, Buttom_Gap, Right_Gap);
}
于 2013-10-31T11:53:00.873 回答
0

您是否尝试将单元格的最小间距设置为负值,如果没有这样做,请转到UICollectionView您的 xib 并选择检查器并在那里自定义最小空间。我有一张图片告诉你我的意思:

集合视图检查器

于 2013-08-04T22:37:11.057 回答