This implementation is from a tableView that is using coreData & fetchRequests as the model. It's necessary to implement the following dataSource delegate methods. Also there is a simple method in the table's data class which selects for 'first character'.
in WordsTableViewController.m - implement the following delegate methods
#pragma mark - UITableViewDataSource indexList Methods
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return [self.fetchedResultsController sectionIndexTitles];
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
return [self.fetchedResultsController sectionForSectionIndexTitle:title atIndex:index];
}
in Items.m - this method uses the 1st character of each word as it's index
-(NSString *)firstChar {
return [self.word substringToIndex:1U];
}
in WordTableViewController.m - And most importantly in the (void)setupFetchedResultsController method the firstChar is used as the sort parameter.
self.fetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest:request
managedObjectContext:self.wordDictionary.managedObjectContext
sectionNameKeyPath:@"firstChar"
cacheName:nil];
ref: myDictionary by CPL