当重新排序其他单元格时,如何使UICollectionView的单元格忽略位置更改?

时间:2016-05-03 10:15:03

标签: ios objective-c uicollectionview

当重新排序其他单元格时,如何使UICollectionView的单元格忽略位置更改?

例如

初始细胞

  

========= cell1 cell2 cell3 cell4 ==========

将cell4移动到cell1,它将是

  

========= cell4 cell1 cell2 cell3 ==========

现在,我想 忽略cell3位置更改 ,它应该是

  

========= cell4 cell1 cell3 cell2 ==========

我正在使用此API进行重新排序:

- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath;

2 个答案:

答案 0 :(得分:1)

- (NSInteger)collectionView:(UICollectionView *)theCollectionView numberOfItemsInSection:(NSInteger)theSectionIndex {
    return DisplayCollOrderAlbumArrImages.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    LivresCollectionOrderVCCell *playingCardCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath];

    [playingCardCell.aImageView setImageWithURL:[DisplayCollOrderAlbumArrImages objectAtIndex:indexPath.row]   placeholderImage:[UIImage imageNamed:@"noimgavailable.png"]];

    return playingCardCell;
}

- (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath willMoveToIndexPath:(NSIndexPath *)toIndexPath {
    NSString *imagename = DisplayCollOrderAlbumArrImages[fromIndexPath.item];

    [DisplayCollOrderAlbumArrImages removeObjectAtIndex:fromIndexPath.item];
    [DisplayCollOrderAlbumArrImages insertObject:imagename atIndex:toIndexPath.item];
}

答案 1 :(得分:1)

根据我的理解,你想要交换两个单元格的位置。它可能与this question重复。

另外,您可以refer