Cocoa NSOutlineView和Drag-and-Drop [英] Cocoa NSOutlineView and Drag-and-Drop

查看:179
本文介绍了Cocoa NSOutlineView和Drag-and-Drop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始了另一个没有帐号的线程,所以我在这里用一个帐号转发了这个问题,所以我可以编辑当前链接的程序,以便其他用户可以遵循这一点。我也更新了下面的代码。这是我的原始问题:



我在Outlineviews和DND上阅读了另一篇文章,但是我无法让我的程序工作。这个帖子的底部是我的项目的链接。它非常基本,只有一个轮廓和按钮。我想要接收文本文件被丢弃,但我的代码或连接有问题。我尝试跟随他们的NSOutline拖放苹果的示例代码,但我错过了一些东西。 1的区别是我的程序是一个基于文件的程序,他们的例子不是。我设置文件的所有者接收委托操作,因为这是我的代码处理拖放的地方,以及按钮操作。它可能是一个简单的错误,所以有人可以看看它,告诉我我做错了什么?以下是该文件的链接: http://dl.dropbox.com/u/ 7195844 / OutlineDragDrop1.zip

解决方案

您没有回应NSOutlineView的拖拽验证信息。



您的原始代码已实施的tableView:validateDrop:proposedRow:proposedChildIndex:。正如我在这个问题上指出的那样,当你的表格视图是一个大纲视图时,这是错误的; NSOutlineView将不会发送一个表视图拖动验证消息,只能发送一个大纲视图拖动验证消息。



您已经更改了要声明的拖动验证方法如下所示:


   - (NSDragOperation)outlineView:(NSOutlineView *)view 
validateDrop :(id< NSDraggingInfo>)info
proposedRow:(int)row
proposedChildIndex:(NSInteger)index


但实际上没有发送这样的消息。



记住NSOutlineView很少处理行索引,因为那些可以随着父行展开和折叠而改变。它代之以项目,通常是模型对象。



因此,正确的验证方法是:



< blockquote>

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


请注意选择器的第三个组件的名称以及与之相关的参数的类型和名称。



应用此更改后,您的数据源将验证掉落。


I recently started another thread without an account, so I'm reposting the question here with an account so I can edit current links to the program so other users can follow this. I have also updated the code below. Here is my original question:

I read the other post here on Outlineviews and DND, but I can't get my program to work. At the bottom of this post is a link to a zip of my project. Its very basic with only an outlineview and button. I want it to receive text files being dropped on it, but something is wrong with my code or connections. I tried following Apple's example code of their NSOutline Drag and Drop, but I'm missing something. 1 difference is my program is a document based program and their example isn't. I set the File's Owner to receive delegate actions, since that's where my code to handle drag and drop is, as well as a button action. Its probably a simple mistake, so could someone please look at it and tell me what I'm doing wrong? Here is a link to the file: http://dl.dropbox.com/u/7195844/OutlineDragDrop1.zip

解决方案

You're not responding to NSOutlineView's drag-validation message.

Your original code implemented tableView:validateDrop:proposedRow:proposedChildIndex:. As I pointed out on that question, that's wrong when your table view is an outline view; NSOutlineView will not send a table-view drag-validation message, only an outline-view drag validation message.

You've since changed your drag-validation method to be declared like so:

- (NSDragOperation)outlineView:(NSOutlineView*)view
                validateDrop:(id <NSDraggingInfo>)info
                 proposedRow:(int)row
          proposedChildIndex:(NSInteger)index

But nothing actually sends such a message.

Remember that NSOutlineView rarely deals with row indexes, since those can change as parent rows are expanded and collapsed. It deals instead with "items", which are generally model objects.

Therefore, the correct validation method is:

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

Notice the name of the third component of the selector, and the type and name of the argument that goes with it.

With this change applied, your data source validates drops.

这篇关于Cocoa NSOutlineView和Drag-and-Drop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆