I've got implemented Drag and Drop from Finder to my app to NSTableView, and I created link
to document, etc.
But, I want to make delete operation by drag item from NSTableView and drop this row onto Trash icon. How can I do this correctly? How enable drop onto trash?
(It's been a long time since I've done this, and I'm doing it from memory and a glance at the docs. If this doesn't work, let me know and I'll double check w/ code.)
In draggingSession:sourceOperationMaskForDraggingContext:
you should include NSDragOperationDelete
as one of the legal operations. You will then receive NSDragOperationDelete
back in your draggingSession:endedAtPoint:operation:
to indicate that the item was dropped on the trash.
Use dropSessionDidEnd delegate method. there you can get the location of dropping point and there's no need for another UICollectionView/UITableView :
func collectionView(_ collectionView: UICollectionView, dropSessionDidEnd session: UIDropSession) {
guard let item = session.items.first?.localObject as? YourObject else {
return
}
let dropLocation = session.location(in: self.view)
let itemDropedInTrash = TrashImageView.frame.contains(dropLocation)
if itemDropedInTrash {
//here update your datasource and reload your collectioView/tableView
//deleteItemFromDataSource(item: item)
//collectionView.reloadData()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With