Dragging into an NSTableView

Drarok

Registered
I'm trying to implement an app with a playlist in, and want to be able to drag a file into it from the Finder.

I've called [tableView registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]] but I don't know if that's the right call?

I've also implemented - (BOOL)tableView:(NSTableView*)tableView acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)operation with NSLog-ing to keep track of what's going on.

But nothing really seems to happen, it doesn't accept the drag at all.
Anyone got a really simple example of how to do this?

Cheers guys.
 
Make sure you're calling registerForDraggedTypes from awakeFromNib, not init.

You have to also implement tableView:validateDrop:proposedRow:proposedDropOperation

See here for more info.
 
I was indeed calling it in awakeFromNib. Got messages flying around now, cheers. Can't seem to work out how to get the filename from the operation :/
 
Use the "info" variable in validateDrop (it's of type NSDraggingInfo), which has a member variable draggingPasteboard, which returns an NSPasteboard. Then on the pasteboard, call propertyListForType with type NSFilenamesPboardType. It should return an NSArray, or something like that :)
 
Ooooh, I get it. got the propertyListForType: thing working, it now adds the files I drop.
Many thanks! :D
Just gotta parse the file path for the name alone and tidy it a bit.
 
Back
Top