views:

59

answers:

1

I have a Cocoa App that I have manually added core data to. I setup the table in Interface Builder to list the entities from the data (with NSArrayController), and this is working just fine. The problem is when I insert a new entity (via code) the table does not update until I restart the app.

What do I have to do after inserting an entity and saving the context to get the table to automatically pick up the changes?

+1  A: 

I'll assume you mean you want to update your array controller's contents, allowing the table to update as a result.

Short answer: Send your array controller a -fetch: message.

Longer answer: Only entity instances added through an array controller automatically show up in its contents array when it gets its contents via a straight fetch request (ie, when its contents array isn't bound to anything, but rather you set an entity name and a MOC, possibly a predicate, and nothing else).

Joshua Nozzi
Thanks. I tried sending the fetch message after saving and that didn't do anything. Can you point me to some information or samples of how to implement your "longer answer"? I'm new to objective-c and cocoa and am having trouble finding information on topics like these.
Jeremy Gillick
The longer answer is an explanation of the short answer. :-) After you create an instance of your entity, have you tried asking the managed object context to -processPendingChanges?
Joshua Nozzi