I would like be able to drag (any) file to my view-based NSTableView, so in the delegate I have this setup:
class MyViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource, NSDraggingDestination
{
@IBOutlet var tableView: NSTableView! // connected in storyboard.
override func viewDidLoad()
{
super.viewDidLoad()
tableView.registerForDraggedTypes([NSFilenamesPboardType])
// …
}
func draggingEntered(sender: NSDraggingInfo) -> NSDragOperation
{
println("Drag entered.")
return .Copy
}
func prepareForDragOperation(sender: NSDraggingInfo) -> Bool
{
return true
}
func draggingUpdated(sender: NSDraggingInfo) -> NSDragOperation
{
return .Copy
}
// ...
}
But my program just refuses to react to a drag-n-drop. When I drag a file from Finder to it and release, the file icon just flies back to Finder. Am I missing something in my code?
UPDATE: I added this
func performDragOperation(sender: NSDraggingInfo) -> Bool
{
return true
}
but it still doesn’t work. Should I implement this in my view instead of the delegate? The document says “Either a window object or its delegate may implement these methods;”