Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bindings Problem: [change valueForKey:NSKeyValueChangeIndexesKey] always returns NULL!!



Hi everyone.

Its been a long time since I posted to these lists!
Well, I've got a problem.

I've got a custom graphics view that is bound to an NSTreeController that provides the content for said custom view.
Its set up to be bound to the NSTreeController, and I have registered as an observer using:
[controller addObserver:self forKeyPath:@"arrangedObjects" options: (NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context: (id)CONTENT_CONTEXT];


The Code that observes changes are as follows:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == CONTENT_CONTEXT) {
NSKeyValueChange changeKind = [[change valueForKey:NSKeyValueChangeKindKey] intValue];

if (NSKeyValueChangeRemoval == changeKind) {
//Remove old Values
NSArray *changedIndexes = [change valueForKey:NSKeyValueChangeIndexesKey];
NSArray *objectsToRemove = [change valueForKey:NSKeyValueChangeOldKey];
NSLog(@"Changed Indexes are %@, removedObjects are %@",changedIndexes,objectsToRemove);
}

if (NSKeyValueChangeInsertion == changeKind) {
//Insert new Values
NSArray *changedIndexes = [change valueForKey:NSKeyValueChangeIndexesKey];
NSArray *objectsToInsert = [change valueForKey:NSKeyValueChangeNewKey];
NSLog(@"Changed Indexes are %@, inserted indexes are %@",changedIndexes,objectsToInsert);
}

if (NSKeyValueChangeReplacement == changeKind) {
//Remove old Values and replace with new ones
}

if (NSKeyValueChangeSetting == changeKind) {
//Remove all old Values and replace with all new ones
NSArray *changedIndexes = [change valueForKey:NSKeyValueChangeIndexesKey];
NSArray *objectsToInsert = [change valueForKey:NSKeyValueChangeNewKey];
NSArray *objectsToRemove = [change valueForKey:NSKeyValueChangeOldKey];

NSLog(@"Changed Indexes are %@, inserted indexes are %@, removedObjects are %@",changedIndexes,objectsToInsert,objectsToRemove);

}



Here the NSLog always prints out:
Changed Indexes are (null), inserted indexes are <null>, removedObjects are <null>


Furthermore, the only changes that seem to get registered from the NSTreeController are NSKeyValueChangeSetting. I never get NSKeyValueChangeInsertion for example....
IOW, NSTreeController, like NSArrayController, doesn't insert new or remove single additions or removals, it removes and the reinserts everything at once....
Aside from not even being able to get the changed indexes, how am I supposed to efficiently program a view with many items, when I have to remove and add everything over and over again??


After looking at MMalc's bindings examples, I came across this gem:

		/*
		 Should be able to use
		 NSArray *oldGraphics = [change objectForKey:NSKeyValueChangeOldKey];
		 etc. but the dictionary doesn't contain old and new arrays.
		 */

Great!! So uh, what am I supposed to do???


Any help would be appreciated!



_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.