끌어서 놓기 대리자 메서드를 사용하여 NSCollectionView
안에있는 항목을 이동하고 싶습니다. 아이템이 떨어질 때까지 작동합니다. 목적지 표시기 (갭)가 없으며 마우스를 놓을 때 아이템이 튀어 오릅니다. 대표단 validateDrop
과 acceptDrop
은 절대 호출되지 않습니다. CollectionViewItems
사용자 정의 개체에서 데이터를 보여주고있다 : NSCollectionView 내부의 끌어서 놓기 예제
func collectionView(_ collectionView: NSCollectionView, canDragItemsAt indexPaths: Set<IndexPath>, with event: NSEvent) -> Bool {
print("canDragItem", indexPaths)
return true
}
func collectionView(_ collectionView: NSCollectionView, writeItemsAt indexPaths: Set<IndexPath>, to pasteboard: NSPasteboard) -> Bool {
let indexData = Data(NSKeyedArchiver.archivedData(withRootObject: indexPaths))
pasteboard.declareTypes(["my_drag_type_id"], owner: self)
pasteboard.setData(indexData, forType: "my_drag_type_id")
print("write data", indexData)
return true
}
func collectionView(_ collectionView: NSCollectionView, validateDrop draggingInfo: NSDraggingInfo, proposedIndex proposedDropIndex: UnsafeMutablePointer<Int>, dropOperation proposedDropOperation: UnsafeMutablePointer<NSCollectionViewDropOperation>) -> NSDragOperation {
print("validation")
return NSDragOperation.move
}
func collectionView(_ collectionView: NSCollectionView, acceptDrop draggingInfo: NSDraggingInfo, index: Int, dropOperation: NSCollectionViewDropOperation) -> Bool {
let pb = NSPasteboard()
let indexData = (pb.data(forType: "my_drag_type_id"))! as Data
let indexPath = (NSKeyedUnarchiver.unarchiveObject(with: indexData)) as! IndexPath
let draggedCell = indexPath.item as Int
print("acceptDrop", draggedCell)
return true
}
는 도대체 ... 내가 대지에 드래그 할 수있는 항목 데이터를 쓰기에 문제가 무슨 생각. 어떤 제안.
메소드의 선언을 확인하십시오. '경로'가 누락되었습니다. – Willeke
@Willeke는 답변 해 주셔서 감사합니다. 그러나 무엇을 의미합니까? 어떤 경로가 누락 되었습니까? 감사! – JFS
'validateDrop'와'acceptDrop' 함수가 올바른 매개 변수를 가지고 있지 않습니다. 새 버전에는'proposedIndexPath' 및'indexPath' 매개 변수가 있습니다. – Willeke