FROM : Patrick Machielse
DATE : Thu Sep 30 22:32:45 2004
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_removed>
DATE : Thu Sep 30 22:32:45 2004
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_removed>
| Related mails | Author | Date |
|---|---|---|
| Patrick Machielse | Sep 30, 22:32 | |
| Jacob Lukas | Oct 1, 00:55 | |
| Scott Stevenson | Oct 1, 01:14 | |
| Scott Stevenson | Oct 1, 01:20 | |
| Jacob Lukas | Oct 1, 01:26 | |
| Scott Stevenson | Oct 1, 02:46 | |
| Jacob Lukas | Oct 1, 03:09 | |
| Scott Stevenson | Oct 1, 05:05 | |
| Jacob Lukas | Oct 1, 08:18 | |
| Christian Brunsche… | Oct 1, 11:03 | |
| Patrick Machielse | Oct 1, 11:24 | |
| Patrick Machielse | Oct 1, 13:26 | |
| Patrick Machielse | Oct 1, 13:35 | |
| Eric Ocean | Oct 1, 17:37 | |
| Scott Stevenson | Oct 1, 23:38 | |
| Scott Stevenson | Oct 1, 23:40 | |
| Patrick Machielse | Oct 4, 13:56 | |
| Steven Kramer | Oct 4, 17:09 | |
| Patrick Machielse | Oct 6, 12:57 | |
| Steven Kramer | Oct 7, 15:02 |






Cocoa mail archive

