I\'m trying to create a sectioned NSTableView
using NSArrayController
and cocoa bindings. I\'m searching for a similar approach like with NSFetch
Though NSTableView
can render group rows, unfortunately it depends on the delegate or data source to flatten the hierarchy. It doesn't understand alternate data source semantics like UITableView
's UITableViewStyleGrouped
, nor does NSArrayController
have equivalents to NSFetchedResultsController
's section methods.
One option is NSOutlineView
which is designed for displaying arbitrarily deep hierarchical data, but it probably creates more work than necessary for a simple two-level structure. (You can bind an outline view to NSTreeController
but the tree controller is poorly documented, and to boot, it's badly designed.)
So, here's what I suggest:
NSTableViewDelegate
and NSTableViewDataSource
.YES
from tableView:isGroupRow:
on the section headings.You could also look for a reusable, bindings-capable controller from a third party.
You have to fill NSArrayController manually with a custom class instances that exactly holds the content of the NSTableView you want to accomplish, including the group rows. The controller must be filled in the correct order. So it should start with a group header object, then some data objects, a new header object, and so on. The custom class should contain the following properties:
isGroupHeader
. Needed for an easy tableView:isGroupRow:
implementation.With this you have all the tools to implement all NSTableView delegates to get a properly grouped table view.
You could try implementing a sectioned NSTableView using the tools mentioned in this answer:
https://stackoverflow.com/a/5369550/893113