How to return the section title in a UITableView with Core Data

- by

Our NSFetchedResultsController can take care of this too:

- (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.

Add your voice!

This site uses Akismet to reduce spam. Learn how your comment data is processed.