NSOutlineView与拖放 [英] NSOutlineView with Drag and Drop

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

问题描述

我在此处阅读了有关Outlineviews和DND的另一篇文章,但无法使我的程序正常工作。这篇文章的底部是我项目的zip链接。它非常基本,仅带有Outlineview和按钮。我希望它接收放在其上的文本文件,但是我的代码或连接出了点问题。我尝试按照Apple的NSOutline拖放示例代码进行操作,但我缺少一些内容。 1个区别是我的程序是基于文档的程序,而示例不是。我将文件所有者设置为接收委托操作,因为这是我处理拖放的代码以及按钮操作的位置。

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?

推荐答案

您实现了是表格视图数据源拖动接收方法,而不是大纲视图数据源拖动接收方法。大纲视图是一种表视图,但它仅使用大纲视图数据源协议;表格视图数据源协议仅适用于表格视图数据源,而不适用于大纲视图数据源。

You implemented the table view data source drag-reception methods, not the outline view data source drag-reception methods. An outline view is a kind of table view, but it uses the outline view data source protocol exclusively; the table view data source protocol is only for table view data sources, not outline view data sources.

请参见 NSOutlineViewDataSource 协议以获取有关在数据源中确切需要实现的详细信息。

See the NSOutlineViewDataSource protocol for more details on exactly what you need to implement in your data source.

关于该注释:您需要在数据源(当前不是您的文档)中实现方法。我不知道你为什么要那样做;通常,文档(主要是控制器)是模型的所有者,因此它应该是数据的视图源-数据源。

On that note: You need to implement the methods in your data source, which is currently not your document. I don't know why you've done it that way; ordinarily, the document (in its role as mostly a controller) owns the model, so it should be the views' source of the data—the data source.

我建议将OutlineDataSource类合并到MyDocument类中,然后将表视图的拖动接收方法更改为其对应的OutlineView。

I suggest merging the OutlineDataSource class into the MyDocument class, and changing the table view drag-reception methods to their outline-view counterparts.

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

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