Re: Cocoa Bindings Clarification
Re: Cocoa Bindings Clarification
- Subject: Re: Cocoa Bindings Clarification
- From: mmalcolm crawford <email@hidden>
- Date: Sat, 13 Nov 2004 10:34:01 -0800
On Nov 12, 2004, at 1:29 PM, Mark Grimes wrote:
After reading numerous articles and references on Cocoa Bindings, I am
not able to bridge-gap the knowledge for using it on a particular
application I am working on. I see many references to usage in a
NSTableView, but not a lot of references to how one would use it for
other applications.
For example, I have a piece of code I am writing that implements a
NSTask (Cocoa wrapper for UNIX app) for a utility that has MANY
command line switches.
[...]
When I look at the code required to say things like "If this radio
button is checked, then mark the NSTextField's associated with the
other radio
buttons as un-editable (aka grayed out)... it makes me think there has
to be a better way to remove hundreds of lines of updateUI glue-code.
This is illustrated in several examples, even those that use table
views :-) You probably haven't seen it because it's not immediately
obvious in the nib file.
The canonical example is probably the "Delete" button that is only
enabled if is is possible to delete a row... from a table view. Its
'enabled' binding is typically bound to
[ArrayController].canRemove
The two important conceptual issues are:
(a) The binding does not have to be to an instance variable, it can be
to a method that calculates (and returns) a value;
(b) If the value is dependent on other values, then you will have to
use triggerChangeNotificationsForDependentKey to ensure appropriate KVO
notifications are sent for the dependent key when any of keys upon
which it is dependent changes, e.g.
+ (void)initialize
{
[self setKeys:[NSArray arrayWithObjects:@"<key1>", @"<key2", ... nil]
triggerChangeNotificationsForDependentKey:@">dependentKey"];
}
mmalc
_______________________________________________
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