关于 NSoutlineView 和 WriteItem |拖放问题

发布于 2024-10-16 00:46:26 字数 2114 浏览 7 评论 0原文

为了处理 Drag-n-Drop 已完成以下操作,

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

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

WriteItem 方法如下,

- (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;
}

现在我期望控制将到达 AcceptDrop 方法,但断点没有击中那里,并且在 Log/gdb 中获取以下日志

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]

和控制没有'来到acceptDrop方法,

当我启用“异常停止”时,以下是停止时的调用堆栈,

#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

让我再更新一件事,在我的大纲视图中,我有自定义单元格,它只不过是我的Mac ImageTextCell接口文件使用。

谁能指导我,我做错了什么

亲切的问候 罗汉

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

焚却相思 2024-10-23 00:46:26

[myoutlineView setOutlineColoumn:firstColumn] 丢失,
当我添加时,它就开始工作了

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

静待花开 2024-10-23 00:46:26

确保在 Xcode 的“调试”菜单中打开“Stop on Objective-C Exceptions”,然后在调试器下运行应用程序(启用断点)。当抛出异常时,调试器将停止,然后您可以调查在何处尝试使用 nil 对象创建数组。

我发现您所显示的代码不太可能是问题的根源,因为您传递的是 AppKit 框架中全局定义的字符串。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文