Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView reorder unmovable cell issue

I am making a UICollectionView with iOS 9's cool reorder feature. I can make a cell unmovable by returning No in the datasource's function - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath for that index path.

However, I found the cell is able to be replaced with movable items, which is not expected.

For example,

We cannot move the 3rd item (screenshot).

But it is able to be the destination index path for other cell to move to(screenshot).

any good ideas for the 3rd cell to be really fixed?

like image 561
Reeonce Zeng Avatar asked Dec 24 '22 10:12

Reeonce Zeng


1 Answers

Assume item at indexpath = {x,y} cannot be moved. Try use following delegate method.

collectionView(_:targetIndexPathForMoveFromItemAtIndexPath:toProposedIndexPath:)

If the proposed index path is equal to {x,y} then you provide desired index path for the item. Ex {x+1,y}

From the docs:

During the interactive moving of an item, the collection view calls this method to see if you want to provide a different index path than the proposed path. You might use this method to prevent the user from dropping the item in an invalid location. For example, you might prevent the user from dropping the item in a specific section.

like image 146
MadNik Avatar answered Jan 10 '23 02:01

MadNik