2つを分けて使うNSFetchedResultsController's
次に、さまざまなデリゲート メソッドのそれぞれでこれを説明する必要があります。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[self.mainFetchedResultsController sections] count] + 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return [[[self.favFetchedResultsController sections] objectAtIndex:section] numberOfObjects];
} else {
return [[[self.mainFetchedResultsController sections] objectAtIndex:section - 1] numberOfObjects];
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return @"Favourites";
} else {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.mainFetchedResultsController sections] objectAtIndex:section - 1];
return [sectionInfo name];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Object *object = nil;
if (indexPath.section == 0) {
object = [self.favFetchedResultsController objectAtIndexPath:indexPath];
} else {
NSIndexPath *mainIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section -1];
object = [self.mainFetchedResultsController objectAtIndexPath:mainIndexPath];
}
UITableViewCell *cell = ...
...
return cell;
}