我已经实施了acceptDrop
和validateDrop
功能,以及registerForTypes
,但是当我拖动项目时,它甚至都没有显示加号。
extension Document: NSCollectionViewDelegate {
func collectionView(_ collectionView: NSCollectionView, validateDrop draggingInfo: NSDraggingInfo, proposedIndex proposedDropIndex: UnsafeMutablePointer<Int>, dropOperation proposedDropOperation: UnsafeMutablePointer<NSCollectionViewDropOperation>) -> NSDragOperation {
return NSDragOperation.copy
}
func collectionView(_ collectionView: NSCollectionView, acceptDrop draggingInfo: NSDraggingInfo, index: Int, dropOperation: NSCollectionViewDropOperation) -> Bool {
let pasteboard = draggingInfo.draggingPasteboard()
if pasteboard.types?.contains(NSURLPboardType) == true, let url = NSURL(from: pasteboard) as? URL {
do {
try self.addAttachmentAtURL(url)
attachmentsList.reloadData()
return true
} catch let error as NSError {
self.presentError(error)
return false
}
}
return false
}
}
override func windowControllerDidLoadNib(_ windowController: NSWindowController) {
self.attachmentsList.register(forDraggedTypes: [NSURLPboardType])
}