Reorder multiple items in a UICollectionView

127 Views Asked by At

I am using the drag/drop APIs of UICollectionView to support rearranging.

I've implemented the UICollectionViewDragDelegate and UICollectionViewDropDelegate as so (the actual item provider has been omitted for brevity):

func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
    return [UIDragItem(itemProvider: NSItemProvider())]
}

func collectionView(_ collectionView: UICollectionView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem] {
    return [UIDragItem(itemProvider: NSItemProvider())]
}

func collectionView(_ collectionView: UICollectionView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UICollectionViewDropProposal {
    return UICollectionViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
}

func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator) { }

This works fine when only one item is being dragged. However when multiple items are been dragged within the same collection view, collectionView(_:performDropWith:) is never called. There is no issue if the items are dragged from one collection view to another.

Am I doing something wrong or is this scenario not supported?

0

There are 0 best solutions below