Re: NSArrayController and
Re: NSArrayController and
- Subject: Re: NSArrayController and
- From: Erik Stein <email@hidden>
- Date: Mon, 8 Mar 2004 18:06:55 +0100
hi allan --
Am 08.03.2004 um 15:29 schrieb Allan Odgaard:
On 8. Mar 2004, at 10:46, Erik Stein wrote:
My model only has a title and content. No problems with these. Now I
like to have a column in the table view that displays the index of
the model object inside the content array (for that reordering of
items makes sense and is visible in the user interface).
So if I understand you correctly, you have an array of e.g.
dictionaries which you hand over to an array controller and have it
display it in a table view.
I already have a custom class for my model objects, which even
internally does not use a mutable dictionary.
You would like the table view to show one extra column, for which
there is no corresponding key in the dictionaries (i.e. the index).
My problem is that I need a column whose value is dependent on the
whole array (in contrast to just a single item). In my case it's simply
the index of the object within the contentArray, but you could also
imagine more enterprise-oriented stuff like percentage of total count
or standard deviation, or a running total. The code for this should not
be placed in the model object, but in some sort of controller.
And you are wondering where you should place the code to generate the
values for this extra column?
Exactly. From the naming scheme "NSArrayController" (it's not
"NSTableViewController") I would guess that the NSArrayController class
should be responsible for providing array-dependent values (and of
course asking the array's items in the process).
One solution is to drop this "dynamic generation" of the column and
simply store the value in the array items (dictionaries). Another is
to use custom classes instead of dictionaries (but which wrap for a
dictionary) which can generate the value when requested.
I'm using already custom class. The indexInDocument accessor in the
MyCard class (which is accessed via KVC) talks back to the array
controller before the value is dynamically returned. The functionality
for my particular case is working, but I wonder about the general
design principles for cases like this.
Let me summarize my current solution:
1) in MyArrayController's arrangeObjects method I establish a reference
from every model to the controller (via [modelObject
setArrayController:self])*
2) when the item is asked by "the table column" (NSBinder ?) about the
value for it's particular key, the item uses this reference to ask the
array controller about the information it needs, then returns it
Problems:
- it only works if you have a single (array) controller per object in
your setup (because the object stores only one reference)
- it's not clear how good it will work with large arrays
Perhaps I need to file an enhancement request, but this one would be
very unspecific.
Thanks, best regards
-- erik
* of course there is no need to do this in the arrangeObjects: method,
but it's the only place where I don't need to do extra housekeeping
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.