使用两个单独的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;
}