首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在删除/更新核心数据后,NSArrayController有时不会刷新NSTableView

在删除/更新核心数据后,NSArrayController有时不会刷新NSTableView
EN

Stack Overflow用户
提问于 2019-01-26 16:58:32
回答 1查看 155关注 0票数 0

我正在使用NSArrayController绑定从核心数据填充NSTableViewNSArrayController连接到mainQueueConcurrencyType托管对象上下文(主托管对象)。主托管对象上下文的父级是privateQueueConcurrencyType (后台托管对象上下文)。对主托管对象上下文的保存调用将把更改推送到后台托管对象上下文,而对后台托管对象上下文的保存将保存到持久存储中。

在xib中为NSArrayController启用了Prepares contentsEditable

核心数据表:

路径

日期

状态

我将唯一的约束添加到path中。

有时,在保存核心数据后,NSArrayController不会从排列的对象中删除已删除的对象。

代码语言:javascript
复制
  [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
   }];

有谁能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2019-02-01 07:59:40

显然,当上下文中发生变化时,NSArrayController会收到通知。此通知在mergeChangesFromContextDidSaveNotification:中发送,如果automaticallyMergesChangesFromParentYES,则会自动调用该通知。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54376983

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档