Problems with bindings and "continuously updates"

  • Not sure whether this list or Xcode-users is more appropriate, so if
    it should go there, I apologize...

    I'm having some troubles with some read-only bindings.  I have
    several NSString values that are composites of other values (so
    there's no setMyStringValue method, just a myStringValue method), and
    they are not being checked properly by the text fields that are bound
    to them, even when I have "Continuously Updates Value" checked.

    Now, I'm sure this is some kind of newbie mistake (and I'm sure more
    information is needed to diagnose, just not sure what), but what am I
    missing here?

    Thanks very much,

    Timothy Collett

    --

    In my walks, every man I meet is my superior in some way, and in that
    I learn from him.
    -- Ralph Waldo Emerson
  • On 18 Oct 2007, at 9:52 AM, Timothy Collett wrote:

    > I'm having some troubles with some read-only bindings.  I have
    > several NSString values that are composites of other values (so
    > there's no setMyStringValue method, just a myStringValue method),
    > and they are not being checked properly by the text fields that are
    > bound to them, even when I have "Continuously Updates Value" checked.

    Have you called setKeys:triggerChangeNotificationsForDependentKey: in
    your model's +initialize method, so changing the components of your
    composite values will signal a change in your composites?

    — F
  • > I'm having some troubles with some read-only bindings.  I have
    > several NSString values that are composites of other values (so
    > there's no setMyStringValue method, just a myStringValue method), and
    > they are not being checked properly by the text fields that are bound
    > to them, even when I have "Continuously Updates Value" checked.

      You should (re?)read the Key Value Observing Programming Guide:

    http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving
    /index.html


      ... as this information is covered there. In a nutshell, you need to
    implement the method:

    +setKeys:triggerChangeNotificationsForDependentKey:

      ... and register dependent keys. For example, changes to -firstName
    and -lastName should trigger an update on -fullName. As to where to
    implement this and how, read the docs, search Google; the answers are
    there once you know what to look for.

    --
    I.S.
  • > ... as this information is covered there. In a nutshell, you need to
    > implement the method:
    >
    > +setKeys:triggerChangeNotificationsForDependentKey:

      Sorry, confusing terminology. You need to *call* this method.

    --
    I.S.
  • On Oct 18, 2007, at 11:02 AM, Fritz Anderson wrote:

    > On 18 Oct 2007, at 9:52 AM, Timothy Collett wrote:
    >
    >> I'm having some troubles with some read-only bindings.  I have
    >> several NSString values that are composites of other values (so
    >> there's no setMyStringValue method, just a myStringValue method),
    >> and they are not being checked properly by the text fields that
    >> are bound to them, even when I have "Continuously Updates Value"
    >> checked.
    >
    > Have you called setKeys:triggerChangeNotificationsForDependentKey:
    > in your model's +initialize method, so changing the components of
    > your composite values will signal a change in your composites?

    Aha! Thank you very much!

    A newbie mistake indeed.  I shall add that call right away...

    Timothy Collett

    --

    "Few men desire liberty; the majority are satisfied with a just master."
      - Gaius Sallustius Crispus
  • On Oct 18, 2007, at 11:02 AM, Fritz Anderson wrote:

    > On 18 Oct 2007, at 9:52 AM, Timothy Collett wrote:
    >
    >> I'm having some troubles with some read-only bindings.  I have
    >> several NSString values that are composites of other values (so
    >> there's no setMyStringValue method, just a myStringValue method),
    >> and they are not being checked properly by the text fields that
    >> are bound to them, even when I have "Continuously Updates Value"
    >> checked.
    >
    > Have you called setKeys:triggerChangeNotificationsForDependentKey:
    > in your model's +initialize method, so changing the components of
    > your composite values will signal a change in your composites?

    I have a possibly similar situation so I am looking with interest at
    this thread.

    Your suggestion seems very good if he had an instance variable for
    the composite value, but as he said, he has no -setMyStringValue
    method--his composite is generated on the fly with only -
    myStringValue. So is
    setKeys:triggerChangeNotificationsForDependentKey still relevant?
  • On Oct 19, 2007, at 7:39 AM, Paul Bruneau wrote:

    > Your suggestion seems very good if he had an instance variable for
    > the composite value, but as he said, he has no -setMyStringValue
    > method--his composite is generated on the fly with only -
    > myStringValue. So is
    > setKeys:triggerChangeNotificationsForDependentKey still relevant?

    Yes. See <http://developer.apple.com/documentation/Cocoa/Conceptual/
    NSPersistentDocumentTutorial/03_CustomClass/
    chapter_4_section_3.html#//apple_ref/doc/uid/TP40002831-
    DontLinkElementID_47
    > for an example.
  • On 19 Oct 2007, at 7:39 AM, Paul Bruneau wrote:

    > Your suggestion seems very good if he had an instance variable for
    > the composite value, but as he said, he has no -setMyStringValue
    > method--his composite is generated on the fly with only -
    > myStringValue. So is
    > setKeys:triggerChangeNotificationsForDependentKey still relevant?

    Yes. Observable properties need not be instance variables.

    The suggestion is a good one, that a close review of the key-value
    observing protocol would be helpful.

    — F
  • On 19-Oct-07, at 6:39 AM, Paul Bruneau wrote:

    > Your suggestion seems very good if he had an instance variable for
    > the composite value, but as he said, he has no -setMyStringValue
    > method--his composite is generated on the fly with only -
    > myStringValue. So is
    > setKeys:triggerChangeNotificationsForDependentKey still relevant?
    > _______________________________________________

    The problem is that the 'value' of the control changes as a result of
    key/value observation of myStringValue.  The binding option
    "Continuously Updates Value" determines how often myStringValue is set
    as a result of editing the control (which presumably is never).  One
    must ensure that key/value observation of myStringValue occurs as a
    result of key/value observation of the properties on which it
    depends ...

    dave
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today