• 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: Bindings - newbie question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bindings - newbie question


  • Subject: Re: Bindings - newbie question
  • From: Quincey Morris <email@hidden>
  • Date: Mon, 1 Sep 2008 23:08:05 -0700

On Sep 1, 2008, at 22:25, Oleg Krupnov wrote:

What I do:

From within MyDocument's windowControllerDidLoadNib message:

[myController bind: @"currMode" toObject: self withKeyPath:@"currMode"
options:nil];

I do not override bind, unbind etc. of MyController relying on the
default implementation of bindings in NSObject.

Now when the myController's currMode properties changes by its view,
nothing happens in MyDocument. It's setCurrMode is not sent.

What am I doing wrong?

It's counter-intuitive, but 'bind:toObject:withKeyPath:options:' does NOT establish a 2-way binding between two objects. Instead, it's a default implementation of a protocol that is *part* of the behavior you need to implement to have a usable binding.


It's probably not worth bothering with bindings here. Why not just make 'document' a property of the controller, so that you can refer to myDocument.currMode or myController.document.currMode depending on context? It's a LOT easier than getting the 2-way thing working.

I have two accompanying questions:
1) Should I send the bind message to myDocument to observe
myController as well? I used to think that bindings are two-way
inherently, i.e. the object whose "bind" message is invoked, stores
its observed object and when the observer's property changes, it
updates the observed object automatically. Am I wrong?

Yup, the default "bind" message implementation is not inherently 2- way. All of the standard bindings you can set in IB are 2-way, because they're designed that way, and are more than just a front-end to the "bind" message.


2) Am I allowed to send [myController setCurrMode:] in order for the
binding to fire, or am I obliged to always send [myController
setValue:... forKey:@"currMode"] for this?

If you had a usable binding, either form would work. Bindings are implemented on top of KVC/KVO, and both forms are compliant for the property "currMode".




_______________________________________________

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


References: 
 >Bindings - newbie question (From: "Oleg Krupnov" <email@hidden>)

  • Prev by Date: Re: Creating movie on background thread
  • Next by Date: Re: NSArray as a static
  • Previous by thread: Bindings - newbie question
  • Next by thread: Re: Bindings - newbie question
  • Index(es):
    • Date
    • Thread