Skip navigation.
 
mlWhy aren't my bindings firing?
FROM : Charles Srstka
DATE : Fri Jun 27 21:37:56 2008

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

Related mailsAuthorDate
mlWhy aren't my bindings firing? Charles Srstka Jun 27, 21:37
mlRe: Why aren't my bindings firing? Keary Suska Jun 28, 00:17
mlRe: Why aren't my bindings firing? Charles Srstka Jun 28, 00:53
mlRe: Why aren't my bindings firing? Ken Thomases Jun 28, 03:06
mlRe: Why aren't my bindings firing? Charles Srstka Jun 28, 06:08
mlRe: Why aren't my bindings firing? Ken Thomases Jun 28, 08:00
mlRe: Why aren't my bindings firing? Charles Srstka Jun 28, 08:30
mlRe: Why aren't my bindings firing? Ken Thomases Jun 28, 08:57
mlRe: Why aren't my bindings firing? Charles Srstka Jun 28, 10:10
mlRe: Why aren't my bindings firing? Ken Thomases Jun 28, 11:55
mlRe: Why aren't my bindings firing? Steve Weller Jun 28, 16:26
mlRe: Why aren't my bindings firing? Charles Srstka Jun 28, 17:17
mlRe: Why aren't my bindings firing? Charles Srstka Jun 28, 19:31
mlRe: Why aren't my bindings firing? Ken Thomases Jun 29, 08:59
mlRe: Why aren't my bindings firing? Hamish Allan Jun 30, 06:30
mlRe: Why aren't my bindings firing? Charles Srstka Jun 30, 06:33
mlRe: Why aren't my bindings firing? Hamish Allan Jun 30, 06:38
mlRe: Why aren't my bindings firing? Michael Ash Jun 30, 16:56
mlRe: Why aren't my bindings firing? Hamish Allan Jun 30, 23:04
mlRe: Why aren't my bindings firing? Ron Lue-Sang Jun 30, 23:43
mlRe: Why aren't my bindings firing? Hamish Allan Jun 30, 23:53
mlRe: Why aren't my bindings firing? Michael Ash Jul 1, 01:56
mlRe: Why aren't my bindings firing? Ron Lue-Sang Jul 1, 01:58
mlRe: Why aren't my bindings firing? Hamish Allan Jul 1, 21:45
mlRe: Why aren't my bindings firing? Ken Thomases Jul 2, 11:14
mlRe: Why aren't my bindings firing? Scott Anguish Jul 2, 18:31
mlRe: Why aren't my bindings firing? Hamish Allan Jul 3, 01:04
mlRe: Why aren't my bindings firing? mmalc crawford Jul 3, 02:12
mlRe: Why aren't my bindings firing? Scott Anguish Jul 3, 02:13
mlRe: Why aren't my bindings firing? Hamish Allan Jul 8, 00:51
mlRe: Why aren't my bindings firing? Chris Hanson Jul 8, 04:39
mlRe: Why aren't my bindings firing? Ron Lue-Sang Jul 8, 06:29
mlRe: Why aren't my bindings firing? Scott Anguish Jul 8, 12:11
mlRe: Why aren't my bindings firing? Hamish Allan Jul 8, 17:33
mlRe: Why aren't my bindings firing? Scott Anguish Jul 9, 03:43
mlRe: Why aren't my bindings firing? Hamish Allan Jul 9, 06:39
mlRe: Why aren't my bindings firing? mmalc crawford Jul 9, 07:36
mlRe: Why aren't my bindings firing? Scott Anguish Jul 9, 23:39
mlRe: Why aren't my bindings firing? Hamish Allan Jul 13, 23:06
ml[Moderator] Re: Why aren't my bindings firing? Scott Anguish Jul 14, 02:27