BSD

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • key path blues

    5 answers - 1460 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hi all,
    I love KV until I start using key paths
    I have a top level object, KVC compliant, which is hooked to an
    NSController in IB. I have some text fields set to the object's
    values. Everything works fine, I can receive changes made to the text
    fields and also set the text fields' value by invoking accessor
    methods from the top object.
    I have a KVC compliant object in this top level object and have set
    key paths in other text fields to values in this object. I can
    receive changes from the text fields, but changing its values with
    accessor methods, either from the object itself, or from the top
    object, doesn't register a change.
    Examples:
    [self setTempSetpoint:135];// this sets the bound text fields value
    and sets the value in the object
    [[self polCurve] setDwell:3.9]; // this doesn't, but it sets the
    value in the object
    [self setValue:[NSNumber numberWithFloat:3.14]
    forKeyPath:@"polCurve.dwell"]; // this has the same effect as the
    previous command
    any help, much appreciated.
    Dave
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    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:
    %40developershed.com
    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.1 | | 630 bytes | |

    [[self polCurve] setDwell:3.9];
    [self setValue:[NSNumber numberWithFloat:3.9]
    forKeyPath:@"polCurve.dwell"];

    These two methods do the exact same thing, so it's not surprising that
    they're both failing in the same way. What does your -[setDwell:]
    function look like? It should look something like this:
    -(void) setDwell:(float)v
    {
    [self willChangeValueForKey:@"dwell"];
    _dwell = v;
    [self didChangeValueForKey:@"dwell"];
    }

    If you leave off the will/didChangeValueForKey parts, KV doesn't know
    the value has changed and won't update any bound objects.

    HTH,
  • No.2 | | 1114 bytes | |

    Hi Steve,
    No, I had my setDwell function to only change the dwell value. I put
    in your below code and it had no effect.

    Also, I don't put the willChangeValueForKey stuff in my top object
    and yet things work just fine in the text fields. Is this because of
    the NSController attached to the top object is handling such
    things?

    Thanks.

    Dave

    Feb 1, 2007, at 11:10 AM, Stephen Deken wrote:

    >[[self polCurve] setDwell:3.9];
    >[self setValue:[NSNumber numberWithFloat:3.9]
    >forKeyPath:@"polCurve.dwell"];
    >

    These two methods do the exact same thing, so it's not surprising that
    they're both failing in the same way. What does your -[setDwell:]
    function look like? It should look something like this:

    -(void) setDwell:(float)v
    {
    [self willChangeValueForKey:@"dwell"];
    _dwell = v;
    [self didChangeValueForKey:@"dwell"];
    }

    If you leave off the will/didChangeValueForKey parts, KV doesn't know
    the value has changed and won't update any bound objects.

    HTH,
  • No.3 | | 1420 bytes | |

    Feb 1, 2007, at 1:10 PM, Stephen Deken wrote:

    >[[self polCurve] setDwell:3.9];
    >[self setValue:[NSNumber numberWithFloat:3.9]
    >forKeyPath:@"polCurve.dwell"];
    >

    These two methods do the exact same thing, so it's not surprising that
    they're both failing in the same way. What does your -[setDwell:]
    function look like? It should look something like this:

    -(void) setDwell:(float)v
    {
    [self willChangeValueForKey:@"dwell"];
    _dwell = v;
    [self didChangeValueForKey:@"dwell"];
    }

    If you leave off the will/didChangeValueForKey parts, KV doesn't know
    the value has changed and won't update any bound objects.

    This is incorrect. Calling -setFoo: will always trigger a binding
    that is bound to the "foo" key. The will/didChange pair is only
    required if you directly change the variable, or if you change
    something else that the bound key relies on. They can also be used to
    trigger the binding without calling the -setXXX: method.

    Glen

    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)

    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:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.4 | | 1525 bytes | |

    Feb 2, 2007, at 3:27 AM, Dave Sopchak wrote:

    Also, I don't put the willChangeValueForKey stuff in my top object
    and yet things work just fine in the text fields. Is this because
    of the NSController attached to the top object is handling
    such things?

    Possible.

    You rethink about what KV is which is to observe a single object's
    properties/values. If I understand this correct, you have object A
    which uses object B. You register to observe values in object A, so A
    only knows about changes in itself. You have not registered with
    object B to observe any of its values. So, if you want A to notify
    clients of changes in values in B you need to add accessors to A that
    forward the messages to B. Another way would be to have A observe B
    and have object A's observing method call willChangeValueForKey/
    didChangeValueForKey for your @"polCurve.dwell" key path. Also, it
    would have help to see a sample of the code your calling as opposed
    to the code which calls it. (We all know how to call accessors, so
    there is not much to see there.)

    Regards,
    Brian Smith
    http://www.suaveware.com

    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)

    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:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.5 | | 2866 bytes | |

    Hi,
    Thanks to all who have given me their input.

    It seems I don't have (or don't know of) a way to notify the
    NSController attached to my top object of changes to my bottom
    object.

    All of my code, both the callers and the accessors, are boring
    vanilla types. Accessors look like this:
    - (PolarizationCurve *)polCurve
    {
    return polCurve;
    }
    - (void)setPolCurve:(PolarizationCurve *)foo
    {
    PolarizationCurve *old = polCurve;
    polCurve = foo;
    [polCurve retain];
    [old release];
    }

    - (float)anodeSetpoint
    {
    return anodeSetpoint;
    }
    - (void)setAnodeSetpoint :(float)foo
    {
    anodeSetpoint = foo;
    }

    I added registerA and observeValueForKeyPath methods to my
    top object to observe the bottom object, and the
    observeValueForKeyPath does get called when I hit one of the accessor
    methods in the bottom object.

    thing that I cannot figure out how to do is to then ping the
    NSController that a change was made.

    I'd be happy to supply more detailany and all help, much
    appreciated. I want to script this app and I don't think that setting
    values will be a problem, but not being able to get them may pose a
    problem.

    Dave

    Feb 1, 2007, at 1:19 PM, Brian Smith wrote:

    Feb 2, 2007, at 3:27 AM, Dave Sopchak wrote:
    >
    >>

    >Also, I don't put the willChangeValueForKey stuff in my top object
    >and yet things work just fine in the text fields. Is this because
    >of the NSController attached to the top object is handling
    >such things?
    >>

    >

    Possible.

    You rethink about what KV is which is to observe a single object's
    properties/values. If I understand this correct, you have object A
    which uses object B. You register to observe values in object A, so
    A only knows about changes in itself. You have not registered with
    object B to observe any of its values. So, if you want A to notify
    clients of changes in values in B you need to add accessors to A
    that forward the messages to B. Another way would be to have A
    observe B and have object A's observing method call
    for your
    @"polCurve.dwell" key path. Also, it would have help to see a
    sample of the code your calling as opposed to the code which calls
    it. (We all know how to call accessors, so there is not much to
    see there.)

    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)

    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:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com

Re: key path blues


max 4000 letters.
Your nickname that display:
In order to stop the spam: 5 + 4 =
QUESTION ON "BSD"

EMSDN.COM