Search code examples
cocoanstableviewnsarraycontrollernsoutlineviewmaster-detail

Master detail interface with multiple detail table views like Mail.app


I have a Cocoa app with a similar layout like Mail.app:

  • A source list on the left where the user can select one of multiple entries
  • A detail table view in the main content area showing a list based on the selected item on the left

I'd like the selection in the detail table view to be maintained separately for each master item.

Currently I have only one detail table view and one array controller. When the master selection changes, I update the contents binding for the detail array controller.

I think I may need multiple detail array controllers -- one for each entry in the master list.

Is there an easier way/recommended pattern to do this?


Solution

  • You need an array controller for each table. For each detail array controller, you need to bind the contents binding to the selectedObjects key of the master array controller.

    So if you had three array controllers, master, detail1 and detail2, then the content binding of detail1 should be set to master using a key path of selectedObjects.

    The content binding of detail2 should be set to detail1, also using a key path of selectedObjects.

    You don't need to change the contents binding programmatically.