如何暂停 NSFetchedResultsController 的工作?

发布于 2024-10-07 15:37:19 字数 548 浏览 2 评论 0原文

我有一个由 NSFetchedResultsController 提供的 UITableViewController 。用户可以从中调用模态视图控制器,在其中他或她可以输入新数据。首先,我创建一个临时对象,如下所示:

newPtr = [[Entry alloc] initWithEntity:[NSEntityDescription
entityForName:@"Entry" inManagedObjectContext:self.nmocontext]
insertIntoManagedObjectContext:self.nmocontext];

当用户做出选择时,会设置此“临时”对象 newPtr 的属性。

问题在于,当模态 ViewController 可见时,基本 UITableViewController 保持活动状态。在某些情况下,当它意识到 newPtr 的强制属性尚未设置时,它似乎会崩溃(导致崩溃)。

我该怎么做才能阻止 NSFetchedResultsController 查看我的托管对象上下文,直到模态 ViewController 被关闭?

I have a UITableViewController fed by an NSFetchedResultsController. From it, the user can call up a modal ViewController in which he or she can enter new data. As this begins, I create a temporary object as follows:

newPtr = [[Entry alloc] initWithEntity:[NSEntityDescription
entityForName:@"Entry" inManagedObjectContext:self.nmocontext]
insertIntoManagedObjectContext:self.nmocontext];

As the user makes choices, attributes of this 'provisional' object, newPtr, are set.

The problem is that the base UITableViewController remains active while the modal ViewController is visible. It seems to be freaking out (causing crashes) in some cases when it realizes a mandatory attribute of newPtr has not been set yet.

What can I do to stop the NSFetchedResultsController from looking at my managed object context until the modal ViewController is dismissed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴情换悲伤 2024-10-14 15:37:19

Core Data 支持“嵌套”托管对象上下文,这允许灵活的架构,从而可以轻松支持独立的、可取消的变更集。通过子上下文,您可以允许用户对托管对象进行一组更改,然后这些更改可以作为单个事务批量提交给父级(并最终保存到存储中),也可以被丢弃。如果应用程序的所有部分只是从应用程序委托中检索相同的上下文,则这种行为很难或不可能支持。

Core Data supports "nested" managed object contexts which allow for a flexible architecture that make it easy to support independent, cancellable, change sets. With a child context, you can allow the user to make a set of changes to managed objects that can then either be committed wholesale to the parent (and ultimately saved to the store) as a single transaction, or discarded. If all parts of the application simply retrieve the same context from, say, an application delegate, it makes this behavior difficult or impossible to support.

南城追梦 2024-10-14 15:37:19

我自己还没有对此进行测试,但可能的方法是实现 viewWillAppearviewWillDisappear,并将 fetchedResultsController 委托设置为 self >将出现nil将消失

或者

您可以创建一个 NSObject,它在编辑窗口中镜像 NSManagedObject 的属性。一旦用户完成属性编辑(并且您已运行适当的验证规则),您可以将它们传递回 NSManagedObject 实例并让 fetchedResultsController 完成其工作。

I haven't tested this myself but a possible approach would be to implement viewWillAppear and viewWillDisappear, and set the fetchedResultsController delegate to self on will appear and nil on will disappear.

OR

You could create an NSObject that mirrors the attributes of your NSManagedObject in your editing window. Once the user has finished editing the attributes (and you have run the appropriate validation rules) you can pass them back to your NSManagedObject instance and let the fetchedResultsController do its job.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文