Cocoa Custom Cells?

Discussion in 'Mac Programming' started by Soulstorm, Dec 16, 2008.

  1. Soulstorm macrumors 68000


    Feb 1, 2005
    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!
  2. lee1210 macrumors 68040


    Jan 10, 2005
    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.?

  3. Bakerman macrumors member

    Jan 31, 2005
    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...>".
  4. Soulstorm thread starter macrumors 68000


    Feb 1, 2005
    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.

    Attached Files:

  5. kainjow Moderator emeritus


    Jun 15, 2000
    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.

Share This Page