UICollectionView Move Item Method Not Called in iOS 18

Summary

In iOS 18, the UICollectionViewDelegate method

collectionView(_:targetIndexPathForMoveOfItemFromOriginalIndexPath:atCurrentIndexPath:toProposedIndexPath:)

is not being called when moving items in a UICollectionView. This method works as expected in iOS 17.5 and earlier versions.

Steps to Reproduce

  1. Create a UICollectionView with drag and drop enabled.
  2. Implement the UICollectionViewDelegate method:
    func collectionView(_ collectionView: UICollectionView, targetIndexPathForMoveOfItemFromOriginalIndexPath originalIndexPath: IndexPath, atCurrentIndexPath currentIndexPath: IndexPath, toProposedIndexPath proposedIndexPath: IndexPath) -> IndexPath {
        print("🐸 Move")
        return proposedIndexPath
    }
    
  3. Run the app on iOS 18.
  4. Attempt to drag and drop items within the collection view.

Expected Behavior

The method should be called during the drag and drop operation, and "🐸 Move" should be printed to the console.

Actual Behavior

The method is not called, and nothing is printed to the console. The drag and drop operation still occurs, but without invoking this delegate method.

Configuration

  • iOS Version: 18
  • Xcode Version: Xcode 16.0.0

Hi @cloneze , first at all, UICollectionView is probably one of the more complex UIKit class and is in continuous evolution at each iOS release.

Come back to your issue, probably the collection view delegate protocol method mentioned is called during a moving of the cell.

If the drag and drop functionality is implemented, I will try to use this method to trace the movement of the cell during a drag and drop use case:

func collectionView(
        _ collectionView: UICollectionView,
        dropSessionDidUpdate session: any UIDropSession,
        withDestinationIndexPath destinationIndexPath: IndexPath?
    ) -> UICollectionViewDropProposal {
        print("🐸 Move")
        return  UICollectionViewDropProposal.init(operation: .move, intent: .insertIntoDestinationIndexPath)
    }

I tested on a simple app with collection view controller with drag and drop enabled, and it seems that this is called correctly.

Here some details: https://developer.apple.com/documentation/uikit/views_and_controls/collection_views/supporting_drag_and_drop_in_collection_views

Bye Rob

UICollectionView Move Item Method Not Called in iOS 18
 
 
Q