Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Why aren't my bindings firing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why aren't my bindings firing?



Okay, in a project I'm working on, I made the mistake of trying to do something simple with the weird deep magic known as Cocoa Bindings. I've got two classes - let's call them "Foo" and "Bar". Foo's implementation has this in it:

- (void)setDisplayName:(NSString *)name {
    [self willChangeValueForKey:@"displayName"];

    NSLog(@"setting display name to %@", name);

    if(name != ivar_displayName) {
        [ivar_displayName release];
        ivar_displayName = [name copy];
    }

    [self didChangeValueForKey:@"displayName"];
}

whereas Bar's implementation has this:

- (void)setTitle:(NSString *)title {
    [self willChangeValueForKey:@"title"];

    NSLog(@"setting title to %@", title);

    if(title != ivar_title) {
        [ivar_title release];
        ivar_title = [title copy];
    }

    [self didChangeValueForKey:@"title"];
}

Foo and Bar are both instantiated in Interface Builder, and Foo has an outlet to Bar. There's also an NSObjectController that's got its content outlet pointed at Foo. Foo has an outlet called "ivar_controller" that points to that NSObjectController. Foo's also got a method that returns its Bar outlet:

- (Bar *)bar {
    return ivar_bar;
}

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?

Thanks,
Charles
_______________________________________________

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




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.