Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
I am building an application using Cocoa bindings. I have a table view that has many fields. For fields with simple text or simple dates inside, everything works OK. But now, I want to implement something a drag and drop feature that goes like this:

There will be a view (NSView??) on the bottom right of the window, so that the user can drag a file onto it. When the user drags the file, this will converted to plain NSData tat will be associated with the selected item in the NSTableView. Imagine an NSTableView that contains field like "name", "salary" and a field that contains an NSData object.

How can I do this? Will I need to create a custom NSCell? A custom control? I don't know where to start!
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
I'm not too familiar with all of the controls, but it seems to me that NSData is an abstract binary blob. How are you going to present this to a user in a table? Are you only going to allow images to be dragged, and you'll display the image? Why only allow the user to drop into a certain area? Why not allow for the whole window and/or dock icon to allow for dropping of a file, text clipping, etc.?

-Lee
 

Bakerman

macrumors member
Jan 31, 2005
62
7
Sweden
NSCells are not involved in drag and drop. For that you just need to implement some methods in the table view delegate (if you want to enable dragging into the table).

However, if you want to display the NSData in the table view, you most likely need a custom cell if you want something more meaningful than "<NSData 0x032ds032...>".
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
I won't be displaying the data into the table view. I will just have a button that will extract the data into a certain position.

TableView is a subclass of NSView. So, if I implement a drag and drop feature, I should use the methods that I normally use into an NSView, right?

I must clarify that I won't be dragging things into the tableView itself. For each item, I will have a dedicated "drag and drop" space where the user will drag files so that they are converted to NSData and associated with the currently selected item.
 

Attachments

  • Picture 1.png
    Picture 1.png
    12.5 KB · Views: 76

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
NSTableView has its own drag and drop methods you need to implement. I think tableView:writeRowsWithIndexes:toPasteboard: is the main one for dragging rows out of the table.

Edit: sorry forgot you're using bindings. There might be a way to do drag and drop with bindings but I'm not sure.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.