• 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
Boggled By Bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Boggled By Bindings


  • Subject: Boggled By Bindings
  • From: Patrick Machielse <email@hidden>
  • Date: Thu, 30 Sep 2004 22:32:45 +0200

I want to bind to a new ivar of my NSArrayController subclass, but somehow
the change notifications never get send.

What I have:

In my NSArrayController subclass I have an 'infoString' method that returns
an array, depending on the length of 'arrangedObjects'. I have also
implemented +initialize to send a change notification for infoString when
arrangedObjects change.

+ (void)initialize
{
    [[self class] setKeys:[NSArray arrayWithObject:@"arrangedObjects"]
                  triggerChangeNotificationsForDependentKey:@"infoString"];
}

- (NSString *)infoString
{
    int  n = [[self arrangedObjects] count];
    if ( n == 0 )
        return @"no objects";
    else {
        NSString *fmt = @"%d object%@";
        return [NSString stringWithFormat:fmt, n, n > 1 ? @"s" : @""];
    }
}

In IB I bind an NSTextField's value to

         Bind to:(my NSArrayController subclass instance)
  Controller Key:infoString
  Model Key Path:<empty>

This works, but _only once_; at startup the textfield is set to 'no
objects', and subsequent changes to arrangedObjects don't have any effect.
Actually, it doesn't matter what keys I specify for 'triggerChange...'

After much experimenting I tried adding

+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key;
{
    if ( [key isEqualToString:@"infoString"] ) {
        return YES;
    }
    return [super automaticallyNotifiesObserversForKey:key];
}

since it seems NSArrayController doesn't return the default 'YES' value for
all keys (is this documented, somewhere?). Still, no success.

Then, (getting more desperate..) I tried adding the following code to
+initialize

    [[self class] exposeBinding:@"infoString"];

Not sure what exactly that would do, but it wouldn't hurt to try. Again no
luck.

I even tried binding to 'infoString' through a separate NSObjectController.
(yes, desperate!) Alas...

So it seems that there is something preventing me to bind to a new ivar of
an NS(Array)Controller subclass. Or maybe I just missed an essential
ingredient?

Any help or illumination is highly appreciated!


N.B.
I worked around this problem by binding the textfield to 'arrangedObjects'
and creating a value transformer to generate the info string. This works
fine, but I'm still curious to know why binding straight to the
NSArrayController ivar fails...


Patrick
---
Hieper Software

w:   www.hieper.nl
e:  email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Boggled By Bindings
      • From: Scott Stevenson <email@hidden>
    • Re: Boggled By Bindings
      • From: Jacob Lukas <email@hidden>
  • Prev by Date: Re: Newbie question: How do I keep animations going NSProgressIndicator...
  • Next by Date: Re: Boggled By Bindings
  • Previous by thread: Re: Newbie question: How do I keep animations going NSProgressIndicator...
  • Next by thread: Re: Boggled By Bindings
  • Index(es):
    • Date
    • Thread