Re: KVO and bindings question
Re: KVO and bindings question
- Subject: Re: KVO and bindings question
- From: Don Rainwater <email@hidden>
- Date: Fri, 28 May 2004 13:17:02 -0400
The model contains an array of account records, and each account record
has an array of transaction records. The view contains a table that
lists the account names, and selecting a particular account shows a
summary of the account, including the account balance (@sum of one of
the variables in the transaction array). If the balance is less than
zero, I want a text field displayed that says "Your account balance is
less than zero."
After I posted my message, I did some further digging in the docs. (I
know - I should have reversed the two steps.) My first stop was
watching for NSTableViewSelectionDidChangeNotification. This sort of
worked: I received notifications for each click in the account. Four
notifications for each click, to be exact, and each one had a different
NSTableView object. This didn't feel like the right approach.
After a walk around the building, I started looking at value
transformers. This turned out to be the right approach. It was very
easy to implement, and I had two of them done in short order. I think
the hardest part was noticing that -applicationDidFinishLaunching:
(where the value transformers are registered for use) takes a
notification parameter.
On May 28, 2004, at 12:41 PM, mmalcolm crawford wrote:
On May 28, 2004, at 7:40 AM, Don Rainwater wrote:
Also in the summary, I have some text that is only to be displayed
when the balance is negative. I had originally thought to observe
the balance instance variable in the provider record, but that only
changes during the calculation phase, and not when the user is
reviewing the provider summaries. I then thought I might be able to
observe the text field itself, so I added my controller as an
observer of itself, with the key path set to the IBOutlet for the
text field, but observeValueForKeyPath:... doesn't seem to fire as I
flip through the providers.
Finally, I thought I would define an action for the text field,
thinking that the action would fire when the text field changed
values from selecting different providers. The action doesn't fire,
so no joy there either.
So, with most of the summary display bound to fields in the table
records, how can I conditionally set other fields in the summary?
It's still not clear to me exactly what is bound to what, and what
your goal is.
Is it the case, fundamentally, that something you're displaying should
be dependent on the user's current selection?
If so, then the likelihood is that the display binding should be bound
to [ArrayController].selection.whatever
If the value of 'whatever' is dependent on other values that might
change, then establish that dependency with
'triggerChangeNotificationsForDependentKey:'
<http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueObserving/Concepts/DependentKeys.html>
If the value of 'whatever' is not a boolean and you need it to be, use
-- or implement and use -- a value transformer.
Or it may be that I've completely misunderstood your requirements...
mmalc
--
Don Rainwater, Management Specialist
UCit Instructional and Research Computing
University of Cincinnati
email@hidden
_______________________________________________
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.