Custom binding not being updated

  • Hello,

    I have a class that exposes a custom binding, one which I'm trying to
    bind to an NSArrayController. I know the NSArrayController is hooked
    up correctly because several NSTableColumns are bound to it and are
    updating appropriately. The NSArrayController manages Core Data
    entities.

    Here's the relevant code:

    NSString *SERVICE_URL_BINDING_NAME = @"serviceURL" ;



    + (void) initialize
    {
    NSLog( @"Initializing %@" , self ) ;
    [self exposeBinding:SERVICE_URL_BINDING_NAME] ;
    }

    - (void) awakeFromNib
    {
    [self bind:SERVICE_URL_BINDING_NAME
      toObject:_blogAccountsController  // the NSArrayController in
    question
      withKeyPath:@"arrangedObjects.serviceURL"
      options:nil ] ;
    }

    // The KVC-compliant accessors
    - (void) setServiceURL: (NSObject *) serviceURL
    {
    NSLog( @"Setting serviceURL to: %@, value %@" , [serviceURL class] ,
      serviceURL ) ;
    _serviceURL = serviceURL ;
    }

    - (NSObject *) serviceURL
    {
    NSLog( @"serviceURL called" ) ;
    return _serviceURL ;
    }

    The problem is that setServiceURL: only gets called once some time
    during application startup, and it is set to an empty array
    (NSCFArray, value ()). If I add or remove items using the table view
    (which should change the Core Data model), my accessors aren't called.
    Shouldn't they be?

    What am I missing?

    Thanks in advance,

    Mike
  • On Nov 20, 2007, at 5:04 AM, mmalc crawford wrote:

    >
    > On Nov 20, 2007, at 12:20 AM, Mike R. Manzano wrote:
    >
    >> What am I missing?
    >>
    > observeValueForKeyPath...

    Oh yes of course :). I previously had that in my code, but was using
    addObserver:… instead of bind:…. When I put the bind:… code in, I took
    the observeValueForKeyPath:… out. I guess I was confused as to the
    exact relationship of KVC/KVO to bindings (I think I'm clear now).

    I actually spent some hours going over the documentation you
    suggested, as well as some quality time with your GraphicsBindings
    example, before posting the last message. As a KVC/KVO and bindings
    newbie, it's taking a bit to wrap my head around it, so I appreciate
    the help.

    That said, I implemented observeValueForKeyPath…, but it is not being
    called at all when I click the "Add" button in my user interface (this
    button sends the add: action to the NSArrayController I'm binding to).
    The object that's listening's implementation is simple, here is the
    code:

    NSString *SERVICE_URL_BINDING_NAME = @"serviceURL" ;

    @implementation BlogAssimilator

    @synthesize serviceURL=_serviceURL ; // an NSObject *

    + (void) initialize
    {
    NSLog( @"Initializing %@" , self ) ;
    [self exposeBinding:SERVICE_URL_BINDING_NAME] ;
    }

    - (void) awakeFromNib
    {
    NSLog(@"BA awake") ;
    [self bind:SERVICE_URL_BINDING_NAME
      toObject:_blogAccountsController // an NSArrayController
      withKeyPath:@"arrangedObjects.serviceURL"
      options:nil]        ;

    }

    // Just added this method
    - (void)observeValueForKeyPath:(NSString *)keyPath
      ofObject:(id)object
      change:(NSDictionary *)change
      context:(void *)context
    {
    NSLog( @"keyPath changed: %@ on object: %@" , keyPath , object ) ;
    }

    @end

    I have also tried binding to arrangedObjects and
    <arrangedObjects....>. I overloaded the NSArrayController's
    addObserver:forKeyPath:options:context: like this:

    - (void)addObserver:(NSObject *)anObserver
      forKeyPath:(NSString *)keyPath
      options:(NSKeyValueObservingOptions)options
      context:(void *)context
    {
    NSLog( @"BlogAcctArrayController::Adding observer: %@ for key path:
    %@" ,
      [anObserver class], keyPath ) ;
    [super addObserver:anObserver forKeyPath:keyPath
      options:options context:context] ;
    }

    This does output this line:

    BlogAcctArrayController::Adding observer: NSObjectParameterBinder for
    key path: arrangedObjects.serviceURL

    so I'm assuming that the KVO is in place, although I'm not sure what
    an NSObjectParameterBinder is.

    Could there be something else that I'm missing?

    Thanks again,

    Mike
previous month november 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    
Go to today