guitarflow
guitarflow

Reputation: 2970

NSOutlineView drop onto child row not working

I have an NSOutlineView showing a list of items and I'd like to implement a kind of folder structure. A folder can contain any number of items.

When a user creates a blank folder, I'd like to create a little drop area to make it more obvious how to get items inside a folder. The drop area is a child item of the folder. Similar to this:

basic structure

The problem is that I just cannot get the NSOutlineView to highlight the drop area when the user drags an item onto it.

Here's what I have so far:

- (NSDragOperation)outlineView:(NSOutlineView *)outlineView
                  validateDrop:(id <NSDraggingInfo>)info
                  proposedItem:(id)item
            proposedChildIndex:(NSInteger)index
{
    // Drag within the outlineview
    if ([info draggingSource] == outlineView)
    {
        if (self.itemBeingDragged)
        {

            if ([item isKindOfClass:[MyFolder class]] ||
                [item isKindOfClass:[MyDropArea class]])
            {
                return NSDragOperationMove;
            }
            ... other statements (irrelevant here) ...
        }
    }
}

Shouldn't this be enough? I do get a dragging feedback. It's a blue line above or below the drop area but that doesn't help me here.

Ideas anyone?

Upvotes: 0

Views: 146

Answers (2)

guitarflow
guitarflow

Reputation: 2970

It turned out that my code was fine. The problem was that my drop area had an image view covering the whole area with a little image saying: "drop items here".

It appears that the image view intercepted with the highlighting! When I remove the image view, everything works. When I add a button and set the image there instead of creating an image view, it works.

So the image view seems to break the responder chain. This happens regardless of the "Refuse first responder" setting in IB.

This is a tough one. Took me forever to find that. Hope this helps anyone also running into this issue!

Upvotes: 0

Paul Patterson
Paul Patterson

Reputation: 6918

Apple's DragAndDropOutlineView sample project should give you some idea about what's causing the problem:

enter image description here

Notice that two of the check boxes allow you to toggle exactly this behaviour. Have a look through the source code and see if you can work out what they're doing that you aren't. I had a quick look, but without more knowledge of your code, I couldn't come up with an answer (so I'm not really posting this as an answer, more of a comment with a picture!).

Upvotes: 1

Related Questions