0

I'm creating a viewcontroller that contains two separate UICollectionViews. I'm allowing for cells to be dragged from one UICollectionView to another. In the method

-(void)collectionView:(UICollectionView *)collectionView performDropWithCoordinator:(id<UICollectionViewDropCoordinator>)coordinator;

I get the dragged item like this

UIDragItem *item = [coordinator.items objectAtIndex:0];

To determine if the drag originated from the same UICollectionView, I want to check the property sourceIndexPath on the itemobject as documented on https://developer.apple.com/documentation/uikit/uicollectionviewdropitem/2897392-sourceindexpath?language=objc Unfortunately, Xcode keeps telling me Property 'sourceIndexPath' not found on object of type 'UIDragItem *' When I print out item, I clearly see the property is available, the nil value is of no importance here, it indicates the drag source.

<_UICollectionViewDropItem:0x60000189a760 previewSize = {50, 50}; sourceIndexPath = (nil); dragItem = <_UIDropItem: 0x60000240a0a0>>

I'm really stuck here, and feels like I'm forgetting to implement some protocol, but double triple checked and everything seems fine. Thanks!

1
  • Did you ever find a solution for this? I am facing a similar issue where sourceIndexPath is always nil.
    – rmp
    Commented Mar 16, 2023 at 2:30

1 Answer 1

-3

Please try https://cocoapods.org/pods/DragDropiOS This will help you.

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let model = collectionModels[indexPath.item]

        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: DragDropCollectionViewCell.IDENTIFIER, for: indexPath) as! DragDropCollectionViewCell

        cell.updateData(model)

        return cell
    }

Not the answer you're looking for? Browse other questions tagged or ask your own question.