我正在使用NSArrayController绑定从核心数据填充NSTableView。NSArrayController连接到mainQueueConcurrencyType托管对象上下文(主托管对象)。主托管对象上下文的父级是privateQueueConcurrencyType (后台托管对象上下文)。对主托管对象上下文的保存调用将把更改推送到后台托管对象上下文,而对后台托管对象上下文的保存将保存到持久存储中。
在xib中为NSArrayController启用了Prepares contents和Editable
核心数据表:
路径
日期
状态
我将唯一的约束添加到path中。
有时,在保存核心数据后,NSArrayController不会从排列的对象中删除已删除的对象。
[context performBlock:^{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"entity" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"path ==%@", path];
[fetchRequest setPredicate:predicate];
NSError *error = nil;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
SyncStatusEntry *syncStatus = [fetchedObjects firstObject];
NSInteger status = syncStatus.status.integerValue;
context deleteObject:syncStatus];
[context save:nil];
// Sometimes NSArrayController still have this object
}];有谁能帮帮我吗?
发布于 2019-02-01 07:59:40
显然,当上下文中发生变化时,NSArrayController会收到通知。此通知在mergeChangesFromContextDidSaveNotification:中发送,如果automaticallyMergesChangesFromParent为YES,则会自动调用该通知。
https://stackoverflow.com/questions/54376983
复制相似问题