• 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
Monitoring an NSArrayController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Monitoring an NSArrayController


  • Subject: Monitoring an NSArrayController
  • From: Michael Fey <email@hidden>
  • Date: Thu, 9 Aug 2007 09:12:10 -0400

Hello Folks!

We've got a Core Data app that uses bindings to populate an NSTableView from an NSArrayController. Within our controller we need to monitor the NSArrayController for additions, deletions, and changes to its contents, but there's a hurdle that we can't seem to make it over.

We have gone down the path of Key-Value observing and registered our controller as an observer to the NSArrayController like so:
[vegetableController addObserver:self forKeyPath:@"arrangedObjects.name" (NSKeyValueObservingOptionNew| NSKeyValueObservingOptionOld) context:NULL];


Our observer method then looks like this:
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)Object change:(NSDictionary*)change context:(void*)context
{
if ([keyPath @"arrangedObjects.name"]) {
NSKeyValueChange keyValueChangeKind = [((NSNumber *)[change valueForKey:NSKeyValueChangeKindKey]) intValue];

if (keyValueChangeKind == NSKeyValueChangeInsertion)
[self someMethod:[change objectForKey:NSKeyValueChangeNewKey]];
else if (keyValueChangeKind == NSKeyValueChangeRemoval)
[self someOtherMethod:[change objectForKey:NSKeyValueChangeNewKey]];
else if (keyValueChangeKind == NSKeyValueChangeSetting)
[self yaMethod:[change objectForKey:NSKeyValueChangeNewKey]];
else if (keyValueChangeKind == NSKeyValueChangeReplacement)
[self theLastMethod:[change objectForKey:NSKeyValueChangeNewKey]];
}
}


The problem that we're running into is that [change objectForKey:NSKeyValueChangeNewKey] is always coming up null (as is objectForKey:NSKeyValueChangeOldKey). Also, the keyValueChangeKind always seems to be NSKeyValueChangeSetting, even when we're adding to the NSArrayController through the GUI. Can someone point us in the right direction?


Regards, Michael Fey email@hidden



_______________________________________________

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Monitoring an NSArrayController
      • From: mmalc crawford <email@hidden>
  • Prev by Date: Accessing window in NSAlert didEndSelector:
  • Next by Date: Hiding MainMenu.nib contents for NSStatusBar based applicatiton
  • Previous by thread: Re: Accessing window in NSAlert didEndSelector:
  • Next by thread: Re: Monitoring an NSArrayController
  • Index(es):
    • Date
    • Thread