0

In my application I implemented the possibility to drag'n'drop files onto a viewbased NSTableview. The NSTableCellView used by the NSTableView contains three labels (NSTextFieldCell) and one image (NSImageCell). I have defined the allowed DragTypes directly in the used SubClass of NSTableView:

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        if #available(OSX 10.13, *) {
            registerForDraggedTypes([NSPasteboard.PasteboardType.fileURL])
        } else {
            registerForDraggedTypes([kUTTypeFileURL as NSPasteboard.PasteboardType])
        }
        self.draggingDestinationFeedbackStyle = NSTableView.DraggingDestinationFeedbackStyle.regular
    }
    deinit {
        unregisterDraggedTypes()
    }

The rest of the drop operation is performed with the NSTableViewDataSource with the two functions:

func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation) -> Bool
func tableView(_ tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation

So far everything works fine except for one annoying little thing: If I move the mouse over the image in the respective row during the drag process, the selection of the row is cancelled. So simply said: I move the mouse pointer during a drag process in a row of the TableView -> The row is selected as desired and remains this also ... until I move the mouse into the area of the image ... Swash, the selection is gone again. If I move the mouse again from the range of the image into the "rest" of the row the row is again selected.

Can it be that the image also needs the DraggedTypes, and the functions also must be implemented or have I overlooked something (a'la "hey, image, get the drop request to the Superview to continue" :) )? The three labels of NSTableCellView obviously don't need this.

I noticed a similar behavior with NSOutlineView: Drag'n'Drop works fine as long as I don't get to the image of the respective entry.

gkoeder
  • 73
  • 4

1 Answers1

0

Thanks to Willeke for pointing me to the right direction! The problem was solved using image.controlView?.unregisterDraggedTypes() in the init of the cell.

gkoeder
  • 73
  • 4