Complete alphabet for master data section indexes

I implemented a table filled with basic data, and now I'm trying to index it using sections, displaying a side alphabet (in the format of "Contacts as").

In the code below, if I use a commented line, I only have letters for existing sections. But I want the whole alphabet, and so I changed the returned array:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{    
    //return [fetchedResultsController sectionIndexTitles];    

    indexArray = [NSArray arrayWithObjects: @"{search}", @"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J",@"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", @"#", nil];
    return indexArray;
}

All letters are displayed in the side pointer. But now I have to implement a method that returns the index of the selected section, and here I have some problems:

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    //return [fetchedResultsController sectionForSectionIndexTitle:title atIndex:index];

    NSString *correspondingLetter = [indexArray objectAtIndex:index];
    NSUInteger correspondingIndex = [[fetchedResultsController sections] indexOfObject:correspondingLetter];

    NSLog(@"------index:%i\ncorrespondingLetter: %@\ncorrespondingIndex: %i\n", index,correspondingLetter, correspondingIndex);

    return correspondingIndex;
}

, , , , . , , . . ?

,

+5
2

@property (nonatomic, readonly) NSArray *sectionIndexTitles

fetchedResultController.
, , NSNotFound , , , ..

+5

. :

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
}


- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    NSString *correspondingLetter = [[[UILocalizedIndexedCollation currentCollation] sectionIndexTitles] objectAtIndex:index];
    return [[self.fetchedResultsController sectionIndexTitles] indexOfObject:correspondingLetter];
}
+2

All Articles