The Cocoa Controller Layer
Subject:   Slightly different views on the same data?
Date:   2004-04-11 11:38:21
From:   look_to_windward


I've switched over to using NSArrayController for an application I'm developing, and it's a very neat fit for a class I already had in there. Gets rid of lots of the glue code, as you mention. However, I've run into a problem which isn't easy to solve given all the simpler examples that apple and yourself have provided.

I have some controllers which are in charge of an array that I want to present to the user in several ways, but customised each time. For example, one of the controllers has an array which is presented in a table, but also used to populate a popup menu with the array plus a few other items.

The problem comes when I want to customise the views of the data - for example in the popup I'd like to say

array item1
array item...

Before, I had the controller watching for changes in its array, and then manually rebuilding the popup and the menubar menu (again slightly different) when things changed (and of course updating the table as it was the data source).

Ideally I'd like to be able to bind the various objects to different accessors in the controller that returned a slightly modified array depending on where it was being presented. I did try to experiment with manually setting up bindings (since you can't set them up in IB, which is a shame), and I can't seem to get that to work.

The alternative would be to set up a controller for each 'view' on the array, but that doesn't seem right to me (it's tying the controllers very tightly to the different views) - I don't see why you should have multiple controller objects for one array of objects - I'd like to keep all the logic for manipulating that array in one place.

Any help on this would be greatly appreciated. Perhaps I just haven't understood how bindings should work. Closest I've found to a solution is this
filtering example - however that's using a controller for each 'view'. A possible subject for a future article anyway : )

1 to 2 of 2
  1. Slightly different views on the same data?
    2004-05-28 03:42:00  jkp [View]

  2. Slightly different views on the same data?
    2004-04-12 18:35:00  sanguish [View]

1 to 2 of 2