我正在尝试实施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
方法):
这是什么?它发生在模拟器和我的iPad上。我无法找到问题。PBItemCollectionServicer连接已断开连接
感谢您的帮助!如果您需要了解更多信息,请告诉我。我不知道究竟需要什么来调试它。