开发者

Updating NSTableView when enitiy is added to core data

I have a Cocoa App that I have manually added 开发者_Python百科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?


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜