我已经指定了NSF的收割者为财产...
@property (nonatomic, strong) NSFetchedResultsController *controller;
...并安排代表到我的班级。
self.controller.delegate = self;
然后,我落实了标题中提到的方法,并在其中设置了一个断点。
- (void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
=> BREAKPOINT <=
}
我为控制器创建了以下调取请求 :
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Post"];
// ... some sort ...
self.controller = [[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequest
managedObjectContext:self.context
sectionNameKeyPath:nil
cacheName:@"cache"];
现在,我在同一个背景下将一些NSManagedObjects 储存在另一类“邮政”类型的“邮政”类型中,但“代码”中从未称它为“/坚挺” (我的断点在断点中)。
有谁知道哪里出了问题吗?
<强> 更新 # # 1 : 从服务器上获取一些文章并将其存储到上下文的类会使用GCD 自动执行 。 强 >
Update #2: I have tried it in another way due it does not work to use a context in a multithreaded environment. (Thanks to svena)
Now the ServerConnection
runs in an async block (using GCD) and performs a selector on the main thread. This selector method stores the posts in the database and SHOULD update the tableview. Basically, I thought that when I store something in this context the didChangeObject
method should be called automatically? But it does not. :-/
I have added a short sequence diagram to illustrate my current status. Does anyone know why this does not work? Please be patient. I am new to CoreData and Objective-C. :)