Search code examples
objective-ccocoabindingnstableviewnsarraycontroller

Using bindings to implement NSTableView drag'n'drop rearranging?


As something of an amateur Obj-C/Cocoa developer, I've recently been wrestling with enabling drag and drop operations in the NSTableViews of my software. After becoming frustrated with it, something crossed my mind: why are we directly interacting with the table view? Would it not be better to implement drag and drop through removal and reinserting of items via the table's bound NSArrayController instead?

Secondly, why isn't there a more elegant solution for adding such common functionality? This seems like the kind of thing that Apple would want to make drop-dead easy to implement.

Thirdly, forgive me if any of these statements seem ignorant! While I know enough to cobble together various pieces of software, I'm nothing even close to an expert.


Solution

  • I would also check out this post on Red Sweater Software's blog. He offers a drop in subclass of NSArrayController that handles the drag and drop for you. It probably needs a bit of updating if you want to properly support multiple image drags (introduced in Lion), but it would be an excellent place to start.