NSOutlineView with Drag and Drop

心不动则不痛 提交于 2020-01-17 03:22:26

问题


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?


回答1:


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.

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.

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



来源:https://stackoverflow.com/questions/2851647/nsoutlineview-with-drag-and-drop

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