0

为什么当我创建一个CollectionView并使用不同的标识符对两个单元格转换时,后者是彼此相连的? 具有相同标识符的小区具有相同的距离,而不同标识符的小区粘在一起。 这里我的代码:单元格在UICollectionView中相互连接

- (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

目前尚不清楚你的意思。 PictureCells是相互粘在一起的,还是粘在AddCell上的? – rdelmar

+0

当标识符更改时,CollectionViewCell将自身附加到具有不同标识符的另一个单元格。也就是说,我有3个带有AddCell标识符的单元格,以及6个带有PictureCell标识符的单元格。当标识符发生变化并因此从AddCell更改为PictureCell时,最后一个AddCell单元格将其自身附加到第一个PictureCell单元 – Joker

+0

这两种单元格的大小是否不同? – rdelmar

回答

0

您是否尝试将单元格的最小间距设置为负值(如果不是这样),请转至xib中的UICollectionView并选择检查器并在其中自定义最小空间。我要给你一个形象展示我的意思:

CollectionView Inspector

+0

它不起作用 – Joker

1

实现此方法的不同部分的细胞之间获得空间:

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section; 
{ 
    return UIEdgeInsetsMake(Top_Gap, Left_Gap, Buttom_Gap, Right_Gap); 
}