Question

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?

Was it helpful?

Solution

(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.

OTHER TIPS

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()

  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top