Cocoa bindings with an Array...
Cocoa bindings with an Array...
- Subject: Cocoa bindings with an Array...
- From: Jiva DeVoe <email@hidden>
- Date: Wed, 16 Feb 2005 19:52:13 -0700
So I have an array of objects. If I add/remove items to the array, my
observers (via cocoa bindings) all do the right thing. BUT if I change
one of the objects internally, my observers do NOT get notified.
I am reasonably certain I am either not calling the appropriate
willChange/didChange settings or I am simply observing the wrong thing,
but I'm not sure what it is. What's the appropriate way to do this?
Do KVC compliant accessors on items inside an array trigger observing
for observers of the array?
Meaning, if I have an object like this:
@interface Foo: NSObject
{
NSString *bar;
}
-(void)setBar:(NSString *);
-(NSString *)bar;
@end;
and I have a bunch of those in an array... and I am observing that
array perhaps via:
[view bind:@"arrayOfFoo" toObject:fooArrayController
withKeyPath:@"arrangedObjects" options nil];
and in my bind method, I am doing:
if([binding isEqualToString:@"arrayOfFoo"])
{
fooController = [observableObject retain];
[observableObject addObserver:self forKeyPath:keyPath options:0
context:FOO_BINDING_CONTEXT];
fooKeyPath = [keyPath copy];
}
Now, if I add/remove items I get notified - but if I change an instance
of foo in the array, even if I bracket it with something like:
[self willChange:NSKeyValueChangeSetting
valuesAtIndexes:[NSIndexSet indexSetWithIndex:0] forKey:@"arrayOfFoo"];
I don't get any notification.
Should I be observing it some different way? Perhaps using
addObserver:toObjectsAtIndexes:forKeyPath:options:context: ??
Must I observe every item in the array? Couldn't that become expensive?
I think this may be the final thing keeping me from grokking bindings.
;) I hope.
--
Jiva DeVoe
http://www.devoesquared.com
PowerCard - Intuitive Project Management Software for Mac OSX
_______________________________________________
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