2016-05-03 42 views
1

如何使UICollectionView細胞忽略位置變化時,其他細胞重新排序?如何使UICollectionView的細胞忽略位置變化時,其他細胞重新排序?

例如

Inital細胞

=========小區1小區2小區3小區4 ==========

移動小區4到小區1,這將是

=========小區4小區1小區2小區3 ==========

現在,我想到忽略小區3位置變化,它應該是

=========小區4小區1小區3小區2 ==========

我使用這個API進行重新排序:

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

回答

0

據我瞭解,你要交換兩個單元的位置。這可能是this question的重複。您也可以refer

+0

我想做的事情和交換兩個單元格之間有些不同。我想只有一個單元格不會改變位置 –

+0

** [self moveItemAtIndexPath:fromIp toIndexPath:toIp]; ** ---> cell4 to cell1 ** [self moveItemAtIndexPath:toIp + 2 toIndexPath:toIp + 3]; ** ---> cell2到cell3 ** [self moveItemAtIndexPath:toIp + 3 toIndexPath:toIp + 2]; ** ---> cell3到cell2。我們認爲你需要如何做這些多位置切換。我想這部分是合乎邏輯的,就像你想要移動的位置和位置。 – user3300864

0
- (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]; 
} 
+0

謝謝你的回答,我想你不明白我的問題〜 –

+0

@Baraiya Bhadresh:爲你的答案添加一些解釋。另外,這不回答OP。 – UditS