Re: Triggering a Method when a Core Data Property is Altered.
Re: Triggering a Method when a Core Data Property is Altered.
- Subject: Re: Triggering a Method when a Core Data Property is Altered.
- From: Volker in Lists <email@hidden>
- Date: Wed, 7 Oct 2009 19:04:59 +0200
Hi,
awakeFromFetch is only called when the object is loaded from the
persistent store (=fetched). So all newly inserted objects are not
observed.
this might be one reason for not getting triggered for rows 2/3 if
they were not fetched but created. Otherwise I have no idea why it
doesn't work yet-
Volker
Am 07.10.2009 um 18:54 schrieb Joshua Garnham:
Hi,
Ok, I have changed it to awakeFromInsert: and have removed the
observer in the NSManagedObjects dealloc: method.
And have already fixed the performSelector: problem.
So the NSManagedObject sub-class looks like …
- (void) awakeFromFetch {
[self addObserver:[NSApp delegate] forKeyPath:@"name"
options:NSKeyValueObservingOptionNew context:nil];
}
- (void)dealloc {
[self removeObserver:[NSApp delegate] forKeyPath:@"name"];
[super dealloc];
}
… and the App Delegate …
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
[self performSelector:@selector(doSomthing:)];
}
It builds without any warnings but it only half works.
What happens is as follows …
In my table view I have added three rows, each have text fields
bound to the 'name' property.
The method is triggere when I change the text for the first row
however it is not triggered when I change the text for the
other rows. Do you have any idea why this is?
_______________________________________________
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