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

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

问题描述

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



我在Outlineviews和DND上阅读了其他帖子,但我无法让我的程序工作。在这个帖子的底部是一个链接到我的项目的zip。它的基本只有一个outlineview和按钮。我希望它接收文本文件被放在它上面,但我的代码或连接的问题。我试着跟随苹果的示例代码,他们的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 *)view 
validateDrop:(id< NSDraggingInfo>)info
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和拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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