문제

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

  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top