Regarding NSoutlineView and WriteItem | Drag-and-Drop Problem

自作多情 提交于 2019-12-12 02:06:10

问题


To handle Drag-n-Drop have done following,

-(void)InitMyOutlineView{
 - - - - -  - - - - - - - -  -- - - - - - - -  -
 - - - - - - - - - - - - - -- -- - - - - - - - - 
[pMyOutlineView registerForDraggedTypes:
     [NSArray arrayWithObject:NSStringPboardType]];

/* I tried both Yes and No */   
[pMyOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
- - - -  -- - - - - - -- - - - - - - -- - - - - - 
- -- -- - - - - -- - - - - - - - - - -  - -- - - - 
}

The WriteItem method as below,

- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard{
    [self log:@"write Items"];
    NSString *pStr = [NSString stringWithFormat:@"this is the temp string "];
       [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
       [pboard setString:pStr forType:NSStringPboardType];
       [self log:@"returning YES"];
       return YES;
}

Now i am expecting control will come to AcceptDrop method, but break point didn't hit there, and in the Log/gdb getting following log

2011-02-04 16:21:25.435 MyApp[2006:a0f] write Items
2011-02-04 16:21:25.437 MyApp[2006:a0f] returning YES
2011-02-04 16:21:25.439 MyApp[2006:a0f] *** -[NSCFArray initWithObjects:count:]: attempt to insert nil object at objects[0]

and control didn't come to acceptDrop method,

When i enable "Stop on Exception" following is the call stack when it stopped,

#0  0x981b94e6 in objc_exception_throw
#1  0x96ed34cf in -[__NSPlaceholderArray initWithObjects:count:]
#2  0x96efaaa3 in +[NSArray arrayWithObject:]
#3  0x92316dfd in -[NSOutlineView _columnsForDragImage]
#4  0x923f1e32 in -[NSTableView _doImageDragUsingRowsWithIndexes:event:pasteboard:source:slideBack:startRow:]
#5  0x91fea16a in -[NSTableView _performDragFromMouseDown:]
#6  0x91fe89b9 in -[NSTableView mouseDown:]
#7  0x91fe864e in -[NSOutlineView mouseDown:]
#8  0x91f86c68 in -[NSWindow sendEvent:]
#9  0x91e9f817 in -[NSApplication sendEvent:]
#10 0x91e332a7 in -[NSApplication run]
#11 0x91e2b2d9 in NSApplicationMain

Let me update one more thing, in my outline view, i have custom cell, which is nothing but Mac ImageTextCell interface file i am using.

Can anyone please guide me, what i am doing wrong

Kind Regards Rohan


回答1:


[myoutlineView setOutlineColoumn : firstColumn] was missing, when i added then its tarted working




回答2:


Make sure you have “Stop on Objective-C Exceptions” turned on in Xcode's Debug menu, then run your application under the debugger (with breakpoints enabled). The debugger will stop when the exception gets thrown, and then you can investigate where you are trying to create the array with a nil object.

I find it improbable that the code you've shown is the source of the problem, since you are passing a string that is globally defined in the AppKit framework.



来源:https://stackoverflow.com/questions/4897167/regarding-nsoutlineview-and-writeitem-drag-and-drop-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!