【发布时间】:2014-11-14 19:51:41
【问题描述】:
我设置了一个获取请求来检索“用户”项目的一些属性:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
[fetchRequest setResultType:NSDictionaryResultType];
[fetchRequest setPropertiesToFetch:[NSArray arrayWithObjects:companyName, firstName, lastName, completeItems, incompleteItems, objectID, nil]];
[fetchRequest setPredicate:predicate];
[fetchRequest setSortDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:SortOptionCompany ascending:YES],
[NSSortDescriptor sortDescriptorWithKey:SortOptionFirstName ascending:YES]]];
[fetchRequest setFetchBatchSize:kBatchSize];
我初始化我的 NSFetchedResultsController:
NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.context
sectionNameKeyPath:@"sectionIdentifier"
cacheName:nil];
属性“sectionIdentifier”是用户实体的临时属性。但是,当我执行此操作时,我收到消息:
"returned nil value for section name key path 'sectionIdentifier'. Object will be placed in unnamed section"
提取的信息未按需要分组。这是因为我需要获取整个 NSManagedObjects 以使 keyPath 不为零,还是有办法在检索字典时使用 sectionKeyPath?我也尝试过使用 setPropertiesToGroupBy: 没有成功。
【问题讨论】:
-
您是否尝试在要获取的属性数组中包含 sectionIdentifier?
-
@pbasdf 是的,它不起作用,我猜是因为 sectionIdentifier 是一个瞬态属性。我尝试使用 propertiesToFetch: 和 sectionKeyPath: 中的非瞬态属性,结果与问题中显示的消息相同。
-
经过一些测试,我已经能够让 sectionNameKeyPath 工作,但仅限于非瞬态属性。所以这是可能的。但是,如果我使用具有 nil 值的属性,我会收到相同的消息。
-
@pbasdf 如何确保该属性没有 nil 值?当我在 UITableViewCell 文本中显示它时,我试图用于 sectionKeyPath 的非瞬态属性不是 nil。
-
您是否将其包含在您的
propertiesToFetch中?
标签: ios core-data mobile nsfetchedresultscontroller nsmanagedobject