views:

53

answers:

1
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];

if ([tempArray containsObject: [sectionInfo indexTitle]])
{
    [tempArray removeObjectAtIndex:[tempArray indexOfObject:[sectionInfo indexTitle]]];     
    return nil;
}else
{
    [tempArray addObject: [sectionInfo indexTitle]];
    return [sectionInfo indexTitle];

}
return [sectionInfo indexTitle];

}

The code above groups the cells in alphabetical order but displays a blank gray header instead of the appropriate title. Could this possibly be because I did not specify the number of headers? This would naturally be a single header for every letter in the alphabet. Any other ideas why the cell headers would flicker white to gray, gray to white as I scrolled?

+1  A: 

Repeated calls to tableView:titleForHeaderInSection: appear to return alternately [sectionInfo indexTitle] and nil. Why are you surprised?

tc.
I have seen applications where the data is grouped alphabetically. All cells beginning with the letter A under A, B under B, and so on. How would this be accomplished? Am I using the wrong function?
Oh Danny Boy
You are using the correct function, but I can't for the life of me figure out what tempArray is supposed to be doing. Try replacing the whole function body with `return [sectionInfo indexTitle];`
tc.