开发者

Drag and drop not working for NSTableView

开发者 https://www.devze.com 2023-03-06 19:15 出处:网络
I have implemented drag and drop feature in my application. All the functionality are well but when we drag a image in to 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,

- (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 < NSDragging开发者_运维知识库Info >)sender


We need a lot more information.

"...but when we drag a image in to 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? 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? Because that's the only place that you will see -performDragOperation: or -prepareForDragOperation: being called. 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.). 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::

This method is invoked only if the most recent draggingEntered: or draggingUpdated: message returned an acceptable drag-operation value

So, first, you need to make sure you've registered for the drag types you want, then you need to implement -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. 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. Those methods are meant for NSView-based classes. For that reason, NSTableView has the following method defined in the NSTableViewDataSource protocol: 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号