• 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: Why aren't my bindings firing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why aren't my bindings firing?


  • Subject: Re: Why aren't my bindings firing?
  • From: Ken Thomases <email@hidden>
  • Date: Fri, 27 Jun 2008 20:06:44 -0500

On Jun 27, 2008, at 2:37 PM, Charles Srstka wrote:

and in Foo's windowControllerDidLoadNib: method (it's an NSDocument subclass) I've got this:

[[self bar] bind:@"title" toObject:ivar_controller withKeyPath:@"selection.displayName" options:nil];

Now here's the thing: if I call setDisplayName: on Foo, it calls Bar's setTitle: method, exactly as it should. However, if I call setTitle: on Bar, it does *not* end up calling Foo's setDisplayName: method, although it seems like it should. I can change the bind:toObject:withKeyPath:options: invocation above so that it binds Bar directly to Foo without going through the object controller, or I can try going the other way and binding the Foo to the Bar - always I get the same result.

I'm sure I'm doing something stupid and/or missing something really simple, but what?

A binding is not just an automated two-way connection between KVC/KVO- conforming properties.


In particular, the binding name you pass to bind:toObject:withKeyPath:options: is not in the same "namespace" as properties. Binding names are something else. Furthermore, implementing bindings is more than just creating KVC/KVO-conforming properties. A binding is a specific feature of a class which requires a specific implementation. See "How Do Bindings Work?" in the Cocoa Bindings Programming Topics to see code listings which illustrate the work that must be done to make a class support a binding.

http://developer.apple.com/documentation/Cocoa/Conceptual/ CocoaBindings/Concepts/HowDoBindingsWork.html


You might be tempted to create a two-way connection between properties by using KVO. It might work, but I suspect you'll get infinite loops.


As a matter of design, you shouldn't hook two properties up in this way to try to keep them always equal. If they're always equal, why store the data in two places? The state of the application (or document or whatever) should be stored (once) in the model. The controller is responsible for reading the state of the model and configuring the view to reflect that. (Both parts of that may be automated using KVO, but note that both the controller and the view will have to implement specific response to the KVO notifications. The view's specific response is part of implementing a binding.) In response to user manipulation, a view may inform the controller of some action or new value. (Again, this part of the view's behavior may be implemented for a binding, in which case it might inform the controller using KVC.) The controller in turn translates that action or value change into instructions to the model to modify itself. (This is often custom, direct invocation of the model's methods, but may also be done via KVC.)


I responded to a similar question the other day, and that thread may also be helpful: <http://lists.apple.com/archives/cocoa-dev/2008/Jun/ msg01484.html>.


Cheers,
Ken
_______________________________________________

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


  • Follow-Ups:
    • Re: Why aren't my bindings firing?
      • From: Charles Srstka <email@hidden>
References: 
 >Why aren't my bindings firing? (From: Charles Srstka <email@hidden>)

  • Prev by Date: Re: simple question about passing around pointers to objects
  • Next by Date: Re: Opening a Panel
  • Previous by thread: Re: Why aren't my bindings firing?
  • Next by thread: Re: Why aren't my bindings firing?
  • Index(es):
    • Date
    • Thread