Cancel drag due to "NSInvalidArgumentException" exception: attempt to insert a null object

When I try to drag an object from NSOutlineView to another, it usually works, but sometimes it fails for some objects. I get a message:

 *** Canceling drag because exception 'NSInvalidArgumentException' (reason '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]') was raised during a dragging session 

I found out that this happens when I first drag an item along another row of the same table (without releasing it) and then drag it to a new table.

This is the contents of draggedItems in the last function that I can check while dragging and dropping:

 - (id <NSPasteboardWriting>)outlineView:(NSOutlineView *)outlineView pasteboardWriterForItem:(id)item { CBCollectible *collectible = [item representedObject]; return [[collectible UniqueID] stringValue]; } - (void)outlineView:(NSOutlineView *)outlineView draggingSession:(NSDraggingSession *)session endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation { //CBDebug(@"end draggingLeaderIndex %i", session.draggingLeaderIndex); } - (void)outlineView:(NSOutlineView *)outlineView draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint forItems:(NSArray *)draggedItems { FreeAndNil(theDraggedItems); theDraggedItems = [[NSArray alloc] initWithArray:draggedItems]; [session.draggingPasteboard setData:[NSData data] forType:MAIN_VIEW_PASTEBOARD_TYPE]; } - (void)outlineView:(NSOutlineView *)outlineView updateDraggingItemsForDrag:(id<NSDraggingInfo>)draggingInfo { } 

Output Log:

 NSLog(@"draggedItems %@", draggedItems); <__NSArrayM 0x31fa0f0>( <NSTreeControllerTreeNode: 0x1d23750>, child nodes {} ) 

UPDATE : drag and drop registration

 [outlineView1 registerForDraggedTypes:@[MAIN_VIEW_PASTEBOARD_TYPE, NSStringPboardType, NSFilenamesPboardType]]; [outlineView2 registerForDraggedTypes:@[MAIN_VIEW_PASTEBOARD_TYPE, NSStringPboardType, NSFilenamesPboardType]]; 
+6
source share

All Articles