John Wells
John Wells

Reputation: 1149

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.

Upvotes: 0

Views: 1237

Answers (2)

willbur1984
willbur1984

Reputation: 1428

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.

Upvotes: 1

Scott Lahteine
Scott Lahteine

Reputation: 1050

I'm just beginning to get into this area to update my Carbon app to the 21st century, and I've found some good resources to get started through the Developer Center. In particular the WWDC 2011 video Session 120 - View Based NSTableView and the associated projects that go with it, especially TableViewPlayground which demonstrates NSTableCellView based tables both with and without bindings. It demonstrates the use of NSArrayController as well.

It's definitely tricky to get used to the MVC paradigm of Cocoa apps, but the great thing about Cocoa is how quickly you can get a prototype working and just add on as you go. In fact I'm tempted to just start with TableViewPlayground and strip out the bits I don't need.

Upvotes: 1

Related Questions