代码之家  ›  专栏  ›  技术社区  ›  SwiftedMind

在CollectionView中拖放:PBItemCollectionService连接已断开

  •  0
  • SwiftedMind  · 技术社区  · 7 年前

    我正在努力实现 Drag&Drop .以下是我正在使用的方法:

    func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
            // This just gets the view model for the cell at that indexPath
            let rackModel = adapter.object(atSection: indexPath.section) as! RoomListData.RackModel
    
            // My RackModel class conforms to NSItemProviderWriting and Reading
            let itemProvider = NSItemProvider(object: rackModel)
            let dragItem = UIDragItem(itemProvider: itemProvider)
            return [dragItem]
    }
    
    func collectionView(_ collectionView: UICollectionView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem] {
            let rackModel = adapter.object(atSection: indexPath.section) as! RoomListData.RackModel
            let itemProvider = NSItemProvider(object: rackModel)
            let dragItem = UIDragItem(itemProvider: itemProvider)
            return [dragItem]
    }
    
    func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator) {
        // This isn't being called  
        print("okay")
    }
    
    
    func collectionView(_ collectionView: UICollectionView, dragPreviewParametersForItemAt indexPath: IndexPath) -> UIDragPreviewParameters? {
            let preview = UIDragPreviewParameters()
            preview.backgroundColor = .clear
            return preview
    }
    

    我还设置了 dropDelegate dragDelegate 对于 UICollectionView . 拖动是可行的,但当我放下对象时,我会在控制台(和 performDrop 方法(未被调用):

    PBItemCollectionService连接已断开

    这是什么?它发生在模拟器上,也发生在我的iPad上。我找不到问题。

    谢谢你的帮助!如果你需要更多的信息,请告诉我。我不知道调试这个需要什么。

    0 回复  |  直到 7 年前