Binding to values which aren't there
Binding to values which aren't there
- Subject: Binding to values which aren't there
- From: A B <email@hidden>
- Date: Fri, 09 Oct 2009 15:17:48 -0700
I have a situation in which I would like a column in a table that is bound to an NSArrayController to display information that isn't actually in the objects being represented, but is instead the result of an operation that involves a bit of data in that row's object and a separate bit of data in another object.
A simplified example can be though of like this: An instance of NSDocument has an array of People objects and each person object has an array of Note objects. The UI is laid out such that there is a list of people in an NSTableView. Selecting a person in that list causes another list to be populated with the notes associated with that person. Easy, right? Well, actually yes - it is... up to a point.
The problem is that each Note object has a date in it that is used to determine the person's age at the time the note was composed. ) The person's birthday is stored in the Person object.) For various reasons I'd rather not store the age value in the note record, but would rather derive it at view time. My first thought was that a value transformer would do the trick, but unfortunately NSValueTransformers are global and not document-specific, so there's no ready way to have the transformer know what the currently selected person of the appropriate document might be. Long-held habits regarding best practices regarding relational integrity are making me reluctant to stick a "parentPerson" ivar in each Note object, otherwise the solution would be simple: Just create another property which has code in the getter that calls back to the parent object (the structure of which would then have to be known to the Note object) for the birthday, does the necessary math and then returns the result.
So my question boils down to this: Is there a way I can intercept the tableview's call to the Note object for the faked-out "fauxValue" column so that I can do the math and return it from a place where scope is less of an issue? Am I even thinking in the right direction here or have I over-thought it to the point where I'm now making it harder than it needs to be?
_______________________________________________
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