• 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
Why aren't my bindings firing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why aren't my bindings firing?


  • Subject: Why aren't my bindings firing?
  • From: Charles Srstka <email@hidden>
  • Date: Fri, 27 Jun 2008 14:37:56 -0500

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


  • Follow-Ups:
    • Re: Why aren't my bindings firing?
      • From: Ken Thomases <email@hidden>
    • Re: Why aren't my bindings firing?
      • From: Keary Suska <email@hidden>
  • Prev by Date: Extent of NDA concerning iPhone
  • Next by Date: Help with notifications and NSFileHandle threads
  • Previous by thread: Re: Extent of NDA concerning iPhone
  • Next by thread: Re: Why aren't my bindings firing?
  • Index(es):
    • Date
    • Thread