简体   繁体   English

拖放不适用于NSTableView

[英]Drag and drop not working for NSTableView

I have implemented drag and drop feature in my application. 我已经在我的应用程序中实现了拖放功能。 All the functionality are well but when we drag a image in to NSTableView , 所有功能都很好,但是当我们将图像拖到NSTableView

- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender

method is not getting called. 方法没有被调用。

Can any one tell me the reason why this method is not getting called? 谁能告诉我为什么不调用此方法的原因?

Even if I implement this one also... 即使我也实现了这一点

- (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender

We need a lot more information. 我们需要更多信息。

"...but when we drag a image in to NSTableView" “ ...但是当我们将图像拖到NSTableView中时”

What do you mean by "image", and where (what application) are you dragging this image from? 您所说的“图像”是什么意思,您从哪里(什么应用程序)拖动该图像? For example, do you mean an image file (Picture.png) from the Finder that you are dragging to the table view in your application? 例如,您是指要从Finder中拖动到应用程序中的表格视图的图像文件(Picture.png)吗? Or from your own application are you dragging some image from one place to your table view? 还是从您自己的应用程序中将某些图像从一个位置拖到表格视图中?

Is this your own custom subclass of NSTableView ? 这是您自己的NSTableView的自定义子NSTableView吗? Because that's the only place that you will see -performDragOperation: or -prepareForDragOperation: being called. 因为那是您看到-performDragOperation:-prepareForDragOperation:的唯一位置。 By default, NSTableView overrides those primitive NSDraggingDestination methods to implement its own tableview-oriented type of methods like Bavarious mentioned ( -tableView:validateDrop:proposedRow:proposedDropOperation: , -tableView:acceptDrop:row:dropOperation: , etc.). 默认情况下, NSTableView会覆盖那些原始的NSDraggingDestination方法,以实现其自身面向表视图的方法类型,例如提到的-tableView:validateDrop:proposedRow:proposedDropOperation:-tableView:validateDrop:proposedRow:proposedDropOperation: ,- -tableView:acceptDrop:row:dropOperation:等)。 If you are talking about the fact that these methods aren't being called in an NSTableView subclass, then remember what the documentation states for -prepareForDragOperation: : 如果您要谈论的是在NSTableView子类中未调用这些方法的事实,请记住文档中-prepareForDragOperation:指出的内容

This method is invoked only if the most recent draggingEntered: or draggingUpdated: message returned an acceptable drag-operation value 仅当最新的draggingEntered:或draggingUpdated:消息返回可接受的拖动操作值时,才调用此方法。

So, first, you need to make sure you've registered for the drag types you want, then you need to implement -draggingEntered . 因此,首先,您需要确保已注册所需的拖动类型,然后需要实现-draggingEntered

If, on the other hand, you aren't talking about an NSTableView subclass, but an external controller class, then, yes, those performDragOperation: and prepareForDragOperation: aren't called for it. 另一方面,如果您不是在谈论NSTableView子类,而是在谈论外部控制器类,那么,是的,没有为它们调用那些performDragOperation:prepareForDragOperation: In other words, if you have a controller class, say, MDAppController , it's set to be the delegate and datasource of an NSTableView , the -performDragOperation: and prepareForDragOperation: of MDAppController won't be called. 换句话说,如果您有一个控制器类,例如MDAppController ,它将被设置为NSTableView的委托和数据源,则不会调用MDAppController-performDragOperation:prepareForDragOperation: MDAppController Those methods are meant for NSView -based classes. 这些方法适用于基于NSView的类。 For that reason, NSTableView has the following method defined in the NSTableViewDataSource protocol: tableView:validateDrop:proposedRow:proposedDropOperation: . 因此, NSTableViewNSTableViewDataSource协议中定义了以下方法: tableView:validateDrop:proposedRow:proposedDropOperation: If you implement that in your controller class, it should be called, provided you've set the tableView up properly and it's been registered for the types of data you want. 如果您在控制器类中实现该函数,则应调用它,前提是您已正确设置tableView并已针对所需数据类型进行了注册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM