Sectioned NSTableView using NSArrayController

后端 未结 3 2255
南方客
南方客 2021-02-15 10:18

I\'m trying to create a sectioned NSTableView using NSArrayController and cocoa bindings. I\'m searching for a similar approach like with NSFetch

3条回答
  •  花落未央
    2021-02-15 10:44

    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:

    • Write your own controller class which implements NSTableViewDelegate and NSTableViewDataSource.
    • Use a single array controller which sorts by priority, and write your own code to offset the row indexes to accommodate the section headings.
    • Return YES from tableView:isGroupRow: on the section headings.
    • Don't use bindings for this one.

    You could also look for a reusable, bindings-capable controller from a third party.

提交回复
热议问题