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

Hi,


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


none
---
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 : )


Full Threads Newest First

Showing messages 1 through 2 of 2.

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

    There is an option that will automatically insert a NULL value as the first item in the popup or a radio matrix

    look at "Inserts NULL Placeholder"

    http://developer.apple.com/documentation/Cocoa/Reference/CocoaBindingsRef/Concepts/BindingsOptions.html#//apple_ref/doc/uid/20002304/187501

  • Slightly different views on the same data?
    2004-05-28 03:42:00  jkp [View]

    Hi...

    I'm a new cocoa programmer / learner, but this article made perfect sense knowing something about MVC, and also having used a data object in applescript studio.

    I have to say though, I think someone needs to make an attempt to answer the query posted above. This seems to me to be an important limitation if you cannot acheive this affect. Any fruther thoughts from you gurus out there?