且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Cocoa NSOutlineView和Drag-and-Drop

更新时间:2022-10-15 23:21:24

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



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



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


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


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



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



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




   - (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.