cocoaxcodenstableviewcocoa-bindingsnsarraycontroller

Sectioned NSTableView using NSArrayController


I'm trying to create a sectioned NSTableView using NSArrayController and cocoa bindings. I'm searching for a similar approach like with NSFetchedResultsController in iOS, where you can set a section key path. I want to make something similar with NSArrayController.

I give you an example: I have different tasks. Each task has one of three different priorities, low, medium or high. The tasks also has attributes like title, description, date, etc. I want to section or group the tasks by priority (the section key path here is the priority).

You can I solve this problem with bindings and NSArrayController? Do I need multiple NSArrayController or just one?


Solution

  • 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:

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