MacRuby: NSTableView Drag’n Drop Rows
You have an NSTableView with an ordered list of data. Ordering that data is important to the user, and you want to implement drag ’n drop to rearrange the rows.
There are three methods you have to implement in your table delegate to get Drag ’n Drop to work.
tableView(myView, writeRowsWithIndexes:rowIndexes, toPasteBoard:pboard)
Use this method to write your table row data to the pasteboard. Your data will live in the pasteboard while the drag operation occurs.tableView(myView, validateDrop:info, proposedRow:row, proposedDropOperation:op)
This method allows you to do any validation on the proposed drop to make sure that you want to accept the drop.tableView(myView, acceptDrop:info, row:row, dropOperation:op)
This method represents the action of actually dropping the data in your table after the drop was accepted. You rearrange your data source array here.
Want to allow your rows to be dragged to other objects without accepting drops? Simple! Just implement the
tableView(myView, writeRowsWithIndexes:rowIndexes, toPasteBoard:pboard)method.
Shablagoo!
