views:

179

answers:

1

I recently started another thread without an account, so I'm reposting the question here with an account so I can edit current links to the program so other users can follow this. I have also updated the code below. Here is my original question:

I read the other post here on Outlineviews and DND, but I can't get my program to work. At the bottom of this post is a link to a zip of my project. Its very basic with only an outlineview and button. I want it to receive text files being dropped on it, but something is wrong with my code or connections. I tried following Apple's example code of their NSOutline Drag and Drop, but I'm missing something. 1 difference is my program is a document based program and their example isn't. I set the File's Owner to receive delegate actions, since that's where my code to handle drag and drop is, as well as a button action. Its probably a simple mistake, so could someone please look at it and tell me what I'm doing wrong? Here is a link to the file: http://dl.dropbox.com/u/7195844/OutlineDragDrop1.zip

+2  A: 

You're not responding to NSOutlineView's drag-validation message.

Your original code implemented tableView:validateDrop:proposedRow:proposedChildIndex:. As I pointed out on that question, that's wrong when your table view is an outline view; NSOutlineView will not send a table-view drag-validation message, only an outline-view drag validation message.

You've since changed your drag-validation method to be declared like so:

- (NSDragOperation)outlineView:(NSOutlineView*)view
                validateDrop:(id <NSDraggingInfo>)info
                 proposedRow:(int)row
          proposedChildIndex:(NSInteger)index

But nothing actually sends such a message.

Remember that NSOutlineView rarely deals with row indexes, since those can change as parent rows are expanded and collapsed. It deals instead with “items”, which are generally model objects.

Therefore, the correct validation method is:

- (NSDragOperation)outlineView:(NSOutlineView*)view
                validateDrop:(id <NSDraggingInfo>)info
                proposedItem:(id)item
          proposedChildIndex:(NSInteger)index

Notice the name of the third component of the selector, and the type and name of the argument that goes with it.

With this change applied, your data source validates drops.

Peter Hosey