我正在创建一个包含两个独立UICollectionViews的视图控制器。我允许将单元格从一个UICollectionView拖到另一个。在该方法中
-(void)collectionView:(UICollectionView *)collectionView performDropWithCoordinator:(id<UICollectionViewDropCoordinator>)coordinator;我得到的拖拽项如下所示
UIDragItem *item = [coordinator.items objectAtIndex:0];为了确定拖拽是否来自同一个UICollectionView,我想检查item对象上的属性sourceIndexPath,如https://developer.apple.com/documentation/uikit/uicollectionviewdropitem/2897392-sourceindexpath?language=objc上所述。不幸的是,当我打印出item时,Xcode一直告诉我Property 'sourceIndexPath' not found on object of type 'UIDragItem *',我清楚地看到该属性是可用的,nil值在这里并不重要,它指明了拖拽的来源。
<_UICollectionViewDropItem:0x60000189a760 previewSize = {50, 50}; sourceIndexPath = (nil); dragItem = <_UIDropItem: 0x60000240a0a0>>我真的被困在这里了,感觉我忘了实现一些协议,但经过三次检查,一切似乎都很好。谢谢!
发布于 2020-01-29 18:57:39
请尝试使用https://cocoapods.org/pods/DragDropiOS,这将对您有所帮助。
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
}https://stackoverflow.com/questions/59965235
复制相似问题