0xymnds
0xymnds

Reputation: 11

UICollectionViewDelegate method not called in iOS 18 for item movement

I'm experiencing an issue with a UICollectionViewDelegate method not being called in iOS 18, while it works fine in iOS 17.5 and earlier. I'm using Xcode 16.0.0 for development.

The Problem

In my app, I have a UICollectionView with drag and drop enabled. I've implemented the following UICollectionViewDelegate method to handle item movement:

func collectionView(_ collectionView: UICollectionView, targetIndexPathForMoveOfItemFromOriginalIndexPath originalIndexPath: IndexPath, atCurrentIndexPath currentIndexPath: IndexPath, toProposedIndexPath proposedIndexPath: IndexPath) -> IndexPath {
    print("🐸 Move")
    return proposedIndexPath
}

This method works as expected in iOS 17.5 and earlier versions. However, in iOS 18, this method is never called when I try to move items within the collection view.

What I've Tried

Questions

  1. Is anyone else experiencing this issue with iOS 18?
  2. Is this a known bug in iOS 18, or has the behavior of this method changed?
  3. Are there any workarounds or alternative methods to achieve the same functionality in iOS 18?

Code Context

Here's a simplified version of my DragAndDropManager class that implements the UICollectionViewDelegate:

class DragAndDropManager: NSObject, UICollectionViewDelegate {
    // ... other properties and methods ...

    func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    func collectionView(_ collectionView: UICollectionView, targetIndexPathForMoveOfItemFromOriginalIndexPath originalIndexPath: IndexPath, atCurrentIndexPath currentIndexPath: IndexPath, toProposedIndexPath proposedIndexPath: IndexPath) -> IndexPath {
        print("🐸 Move")
        return proposedIndexPath
    }
    
    func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
        // Handle the move
    }

    // ... other delegate methods ...
}

Any insights or suggestions would be greatly appreciated. Thank you!

Upvotes: 1

Views: 160

Answers (0)

Related Questions