iPhone UITableView. How do turn on the single letter alphabetical list like the Music App?

dugla picture dugla · Oct 31, 2009 · Viewed 61.3k times · Source

In the iPhone music app, selecting Artist, Songs, or Albums presents a tableView with a verticl list of single letters at the righthand side of the UI that enables rapid scrolling. How do I enable this functionality in my app?

Cheers, Doug

Answer

zaph picture zaph · Oct 31, 2009

Supply your own index characters:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return[NSArray arrayWithObjects:@"a", @"e", @"i", @"m", @"p", nil];
}

and then:

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString
    *)title atIndex:(NSInteger)index {
        return <yourSectionIndexForTheSectionForSectionIndexTitle >;
}

You will need sections.