• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa Bindings Clarification
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Cocoa Bindings Clarification (From: Mark Grimes <email@hidden>)

  • Prev by Date: Re: crossplatform C++, #ifdef
  • Next by Date: Re: Has anyone used xmllib2 in an X-Code project?
  • Previous by thread: Cocoa Bindings Clarification
  • Next by thread: NSMatrix, multiple selection and editable?
  • Index(es):
    • Date
    • Thread