将enitiy添加到核心数据时更新NSTableView [英] Updating NSTableView when enitiy is added to core data

查看:167
本文介绍了将enitiy添加到核心数据时更新NSTableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Cocoa应用程序,我手动添加了核心数据。我在Interface Builder中设置表来列出数据中的实体(使用NSArrayController),这是工作很好。问题是当我插入一个新的实体(通过代码)表不更新,直到我重新启动应用程序。

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?

推荐答案

我假设你的意思是你想更新你的数组控制器的内容,允许表更新作为结果。

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

简短答案:发送数组控制器a -fetch:消息。

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

更长的答案:只有通过数组控制器添加的实体实例在通过直接获取请求获取其内容时自动显示在其内容数组中(即,不绑定任何东西,而是你设置一个实体名称和一个MOC,可能是一个谓词,没有其他)。

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

这篇关于将enitiy添加到核心数据时更新NSTableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆