[Q] Many array elements observing a few UI elements
[Q] Many array elements observing a few UI elements
- Subject: [Q] Many array elements observing a few UI elements
- From: Daniel Côté <email@hidden>
- Date: Mon, 6 Mar 2006 09:22:03 -0500
The question is: What is the entry point where the observer
registration should be done for elements of a collection?
Here is the context: I have a Core Data-document application where a
large number of entities ("Filters") are controlled by an
NSArrayController.
This is displayed in an NSTableView. There is an attribute in my
Filter entity ("match") that is (or should be) calculated based on
user-provided values taken from the main window.
The user provides two numbers (min and max), and each filter in the
table indicates how well it matches those criteria (with some simple
math). If these values change, I want the "match" criteria to be
recalculated. Obviously what I need to do is register each element
from the NSArrayController (upon insert, add and load) to be an
observer of these two fields (min and max), then I am all set. What
is the appropriate entry point for doing this registration for a
collection?
I have kludged together a few working prototypes or have thought of
some strategies, but they are duct-taped together and never feel
quite right, probably because of my limited knowledge of Core Data
+Binding:
1) create custom NSArrayController, with an outlet connect to "min"
and "max" textfields. When insertObject: gets called, register the
observer. Problem: when reloading a saved file, the observer doesn't
get registered(?).
2) Override NSPersistentDocument awakeFromNib, get arrangedObjects
from the NSArrayController, then register observer one by one
3) override initEntityWith: for the entity, use the
managedObjectContext to recover "min" and "max", which would have to
be made attributes of an entity. Need to create a single entity upon
loading the document, sounds ugly.
4) I thought that creating a many to one relationship between Filter
and some new entity "Criteria" would be right, but the relationship
doesn't get set automatically (I need to create an entity myself then
do (3)).
5) Bind the "min" and "max" to SharedDefaults, which is accessible
globally. then bind during initEntityWith.
6) My simplest solution: use my DocumentController to observe the
"min" and "max" values, if they change setKeyValues for all objects
in NSArrayController's arrangedObjects.
What is the entry point where the observer registration should be
done for elements of a collection? What is the appropriate design
strategy for something like this?
Daniel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden