Re: Using an arraycontroller for different object classes
Re: Using an arraycontroller for different object classes
- Subject: Re: Using an arraycontroller for different object classes
- From: Gideon King <email@hidden>
- Date: Sat, 16 May 2009 14:47:32 +1000
Thanks for the suggestion Ken, but I don't think that would help. In
the mini example, yes I would want the object array for weight to have
the full array, and the object array for the tyre size to have the
filtered array, and as you say, this could be accomplished with
separate controllers. However, this means that for every different
type of object in my application that is visible in the inspectors
(currently we have 9 different classes affected), I would have to have
a different array controller, and where there is a subset of common
attributes across different objects, I would have to have additional
array controllers. I could quite easily end up with 20 array
controllers just to handle it, and I would have to make sure the
bindings were made to the right one that represented the objects which
were applicable to that particular key.
If I had to do that much work, then it would be saying to me that the
whole bindings thing does not work for this scenario.
The thing is that I can almost get there by binding to a non-existent
key that I can interpret in my arraay controller, creating an instance
variable to hold the kvc observations, manually calling the willChange
and didChange on them on setContent, and overriding valueForKey in my
array controller subclass to return only the subset array...but the
problem with that is that I can only return an array, which is of
course not able to be bound to because it is not KVO compliant - which
I presume is why the arrangedObjects returns an
_NSControllerArrayProxy. Unfortunately, as the underscore would imply,
the proxy class is not public, so I can't change it myself, or create
my own one to return.
And I considered dynamically changing the content, but setContent
would cause all the KVO stuff to fire, and therefore update all the UI
for the objects where I wanted a different subset array.
Currently looking into how to use a dynamically responding KVC/KVO
compliant object that can hold my actual array of data and use that
instead, but I'm not sure how the array controller works out whether a
value you return is actually an array or a single value. Seems as if I
am missing some concepts around how this works.
Regards
Gideon
On 15/05/2009, at 1:51 PM, Ken Thomases wrote:
On May 14, 2009, at 7:07 PM, Gideon King wrote:
Hi, I have a situation where I have an array of objects that I want
to bind to so I can use them in an inspector, but the objects are
of different classes, and I want the inspector to only see the
objects that have the key that I am binding to.
For example, if I have an array of vehicles, and this array
contains 4 car objects and 2 bulldozer objects. Now I want to have
in my inspector a binding for weight, and one for tyre size.
So for the binding for weight, it is applicable to both classes -
they both have an instance variable called "weight", so the array
would contain 6 objects, but for the binding for tyre size, the
bulldozers don't have tyres, so the array would only have 4 objects
in it.
How should I approach this issue? It appears that the filter
predicates are set on the whole array and would affect everything,
and I have no way to set them based on the key that is being
accesses.
Filter predicates are set on array controllers, not arrays.
Something is controlling what key the inspector is using. Whenever
that decision is made, you can change the filter predicate. You can
do that programmatically with -setFilterPredicate:. You could also
bind the array controller's filter predicate binding to a property
of a coordinating controller, and change that property.
If you have multiple views which are displaying the array, and you
want most to continue showing all of the elements with only the
inspector showing a subset, then you will need multiple array
controllers -- one which is presenting the whole list and another
which is presenting the filtered subset.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden