objective-ccocoadrag-and-dropnsoutlineview

The methods for Drag and Drop in NSOutlineView are not getting called


I'm trying to enable drag and drop functionality for NSOutlineView in my MacOS app. I want to drag a child from a folder to another folder within the outline view.

I want test asset 1 to be dragged and dropped in Group 2

I have myOutlineView and a controller which is a data source and a delegate of my outline view.

In my outline view controller I have these three methods:

-(BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard

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

-(BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id < NSDraggingInfo >)info item:(id)item childIndex:(NSInteger)index

None of them is being called. My nib is setup properly, my outline view is getting filled and all of the functionality is working except the drag and drop feature.

I have also registered the drag type in awake from nib:

[_paraOutlineView registerForDraggedTypes:[NSArray arrayWithObject:@"QStyleSheetModel"]];

I also wrote this:

[_paraOutlineView setDraggingSourceOperationMask:NSDragOperationMove forLocal:YES];

What could be the reason?


Solution

  • I have successfully resolved the issue! Although I couldn't initially pinpoint the exact problem, it turned out that the overridden function "setDataSource" in my code was making a call to an "init" function, which belonged to a different interface. This unexpected call to the "init" function was preventing the execution of "writeItems:toPasteBoard." The solution was to remove the call to the "init" function, and now everything works as expected.