问题描述
当我在Core Data管理对象上下文中插入一个新对象时,不久之后尝试在NSArrayController(通过绑定与managedObjectContext连接)中找到这个新对象,我找不到它。我用一种方法创建和搜索。
When I insert a new object in a Core Data managed object context and shortly after that try to find this new object in the NSArrayController (which is connect with the managedObjectContext through binding), I can't find it. I do the creation and search in one method.
我的问题。
更新:
这是一个新的插入对象在NSArrayControllers arrangeObject数组中显示多长时间?用于插入和获取新对象的代码
Update:Here is the code for inserting and fetching the new objects
NSEntityDescription *entity = [[[self managedObjectModel] entitiesByName] objectForKey:@"EntityName"];
NSManagedObject *object = [[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:[self managedObjectContext]];
...
[[self managedObjectContext] processPendingChanges];
[arrayController fetch:nil];
NSArray* objects = [arrayController arrangedObjects]; //the new object is not present in the array
推荐答案
只是找到了一个修复这个。我使用 NSArrayController
的 setSelectedObjects:
方法来选择对象。不知道为什么我没有使用这种方法!
Just found a fix for this. I use the setSelectedObjects:
method of the NSArrayController
to select the object. Don't know why I didn't used this method anyway!
这篇关于新的Core Data对象不会显示在NSArrayController arrangeObjects中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!