Re: Observing NSArrayController arrangedObjects when there is a fetch predicate
Re: Observing NSArrayController arrangedObjects when there is a fetch predicate
- Subject: Re: Observing NSArrayController arrangedObjects when there is a fetch predicate
- From: Jerry Krinock <email@hidden>
- Date: Fri, 12 Oct 2007 20:14:10 -0700
On 2007 Oct, 12, at 11:34, Andrew Kimpton wrote:
I had hoped that changing the status of an object so that it now
satisfied the predicate on the array controller would cause the
observers to be notified. Is there a different key on the Array
Controller I should be observing ? Something extra I should do to
cause the controller to automatically update and call my observer ?
That array controller may be observing an entity in your managed
object context, but it's not observing all the properties of all the
managed objects, and even if it was, it's probably not going to
'rearrange' its objects (that is, run its sort and filter predicates)
in response. Try to give it a kick with something like this...
- (void)awakeFromNib {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector
(modelChanged:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:nil] ;
}
- (void)modelChanged:(NSNotification*)notification {
[[self arrayController] rearrangeObjects] ;
// Maybe do other business logic stuff too
// ...
}
I admit that the above solution is kind of a shotgun, but the more
focused approaches I've tried in problems like this caused me to
scratch alot of hair off my head, and often ended up throwing
infinite loops in obscure corner cases. If you're lucky, some Core
Data expert out there might have a better answer.
Have fun. Oh, and don't forget to removeObserver:: when you dealloc
that thing ;)
_______________________________________________
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