0
我在Core Data
中有幾個實體。一個被稱爲EventCluster
,用於支撐和構造Event
對象。設置具有多個實體的FetchedResultsController
所有我想在我UITableView
做的很簡單 - 我想UITableViewSections
是相應EventCluster
對象和部分的每一行是將由eventID
值進行排序的Event
對象。
現在我要做的就是這樣的:
- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:_managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"eventID" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
[fetchRequest setFetchBatchSize:20];
NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:_managedObjectContext
sectionNameKeyPath:nil
cacheName:@"Root"];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
有沒有在這裏設立了NSFetchedResultsController
以包括EventCluster
結構的方便的方法?
嘗試將sectionNameKeyPath設置爲@「EventCluster」 – Koen
@Koen,nah,這是行不通的。崩潰:「實體事件不是按照預期的密鑰」EventCluster「符合密鑰值編碼的。 –
他們在你的模型中沒有關係? – Koen