Our NSFetchedResultsController can take care of this too:
1 2 3 4 5 6 7 8 |
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if ([[self.fetchedResultsController sections] count] > 0) { id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section]; return [sectionInfo name]; } else return nil; } |
First we determine if we have sections at all, and if we do we return their respective titles.