NSFetchedResultsController代表和背景驱动更新 [英] NSFetchedResultsController Delegate and Background driven updates

查看:143
本文介绍了NSFetchedResultsController代表和背景驱动更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑进NSFetchedResultsController问题制定客的管理应用程序。

I ran into NSFetchedResultsController issue developing guest-management application.

应用程序基本上下载的背景客人(使用的NSOperation子类)名单,将它们插入到被管理对象上下文,然后presents他们表视图UI线程。

The application basically downloads list of guests on background (using NSOperation subclass), inserts them to managed object context and then presents them in table view on UI thread.

我想我下面的核心数据多线程规则(我有独立的商务部关于其创建的线程操作,同步我没使用保存通知等我的主要MOC)。

I think that I am following the core data multi-threading rules (I have separate MOC for the operation created on its thread, I synchronize my main MOC using did-save notification etc.).

我不完全理解是NSFetchedResultsController的,这似乎是调用其委托的方法(controllerDidChangeContent等)在后台线程而非主线程导致非法UI更新的行为。

What I do not fully understand is the behavior of NSFetchedResultsController which seems to be calling its delegate methods (controllerDidChangeContent etc.) at background thread instead of main thread which leads to illegal UI updates.

所以我的问题是 - 它是合法的使用NSFetchedResultsControllerDelegate观察到,来自商务部并保存更改通知或NSFetchedResultsControllerDelegate设计成只与主线程上所作的更改工作。

So my question is - is it legal to use NSFetchedResultsControllerDelegate to observe changes that come from MOC did save notification or is NSFetchedResultsControllerDelegate designed to work only with changes done on the main thread?

我不知道如果我的解释是很清楚,如果不是我可以张贴一些code来证明这个问题。

I'm not sure if my explanation is clear enough, if not I can post some code to demonstrate the problem.

推荐答案

我的猜测是,你的MOC并保存通知正在发送的和观察的在后台线程,而不是主事件线程。这将导致 NSFetchedResultsControllerDelegate 来在后台线程发送委托邮件。

My guess is that your MOC did-save notification is being sent and observed on the background thread instead of the main event thread. This would cause the NSFetchedResultsControllerDelegate to send delegate messages on the background thread.

您需要确保你没有保存通知观察者将控制权交给主线程,例如:

You need to make sure your did-save notification observer passes control to the main thread, e.g:

- (void)backgroundMOCDidSaveNotifiaction:(NSNotification *)notification
{
    [uiMOC performSelectorOnMainThread:
         @selector(mergeChangesFromContextDidSaveNotification:)
     withObject:notification waitUntilDone:NO];
}

这篇关于NSFetchedResultsController代表和背景驱动更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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