当我试图拖动&将对象从NSOutlineView
拖放到另一个对象,通常可以正常工作,但有时对某些对象会失败。我收到了消息:
*** Canceling drag because exception 'NSInvalidArgumentException' (reason '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]') was raised during a dragging session
我发现当我第一次将项目拖到同一个表的另一行(不释放它)时会发生这种情况,然后拖到新表中。
这是我在拖动过程中可以检查的最后一个函数中draggedItems的内容:
- (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
{
}
输出日志:
NSLog(@"draggedItems %@", draggedItems);
<__NSArrayM 0x31fa0f0>(
<NSTreeControllerTreeNode: 0x1d23750>, child nodes {}
)
更新:拖动注册
[outlineView1 registerForDraggedTypes:@[MAIN_VIEW_PASTEBOARD_TYPE, NSStringPboardType, NSFilenamesPboardType]];
[outlineView2 registerForDraggedTypes:@[MAIN_VIEW_PASTEBOARD_TYPE, NSStringPboardType, NSFilenamesPboardType]];