[英]Core Data sectionNameKeyPath with Relationship Attribute Performance Issue
[英]Core Data - sectionNameKeyPath with a One to Many Relationship
我在使用關系創建tableView部分時遇到困難。
我有兩個實體,其關系列表為 << ----- >> Item 。
我希望List為Section, Item為行。 我設置了sectionNameKeyPath
用鑰匙路徑@"itemList"
。 這就是我的fetchedResultsController的其余內容
- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
// Fetch Request
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Item"];
[fetchRequest setFetchBatchSize:20];
// Sort Descriptors
NSSortDescriptor *itemSort = [[NSSortDescriptor alloc] initWithKey:@"displayOrderItem" ascending:YES];
NSSortDescriptor *sectionSort = [[NSSortDescriptor alloc] initWithKey:@"displayOrderList" ascending:YES];
NSArray *sortDescriptors = @[sectionSort, itemSort];
[fetchRequest setSortDescriptors:sortDescriptors];
// Fetched Results Controller
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"itemList" cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
NSError *error;
if (![self.fetchedResultsController performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
return _fetchedResultsController;
}
結果是fetchedResultsController根本沒有填充tableView。 當我嘗試沒有部分時,使用sectionNameKeyPath:nil
和setSortDescriptor:itemSort
,它會填充tableView。 此外, numberOfSectionsInTableView
和controller didChangeSection
已正確設置。
我不確定我做錯了什么。 任何人都可以幫我嗎?
謝謝
將段名稱鍵路徑更改為itemList.listName
因為FRC期望該段的字符串名稱,而不是“表示”該段的托管對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.