Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a cell of UICollectionView ignore position change when the other cells are reordered ?

How to make a cell of UICollectionView ignore position change when the other cells are reordered ?

For example

Inital cells

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

Move cell4 to cell1, it will be

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

Now, I want to ignore cell3 position change, it should be

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

I am using this API for reordering:

- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath;
like image 587
shi xiaoda Avatar asked Jan 17 '26 19:01

shi xiaoda


2 Answers

According to what I understand, you want to swap the position of two cells. It is possible duplicate of this question.

Also, you can refer.

like image 153
user3300864 Avatar answered Jan 20 '26 11:01

user3300864


- (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];
}
like image 43
Baraiya Bhadresh Avatar answered Jan 20 '26 10:01

Baraiya Bhadresh