Creating Header Titles

It takes little work to add section headers to your grouped table. The optional tableView:titleForHeaderInSection: method supplies the titles for each section. It’s passed an integer. In return, you supply a title. If your table does not contain any items in a given section or when you’re only working with one section, return nil:

// Return the header title for a section - (NSString *)tableView:(UITableView *)aTableView     titleForHeaderInSection:(NSInteger)section {     NSString *sectionName = [crayons nameForSection:section];     if (!sectionName) return nil;     return [NSString stringWithFormat:         @"Crayon names starting with '%@'", sectionName]; }

If you aren’t happy using titles, ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.