views:

891

answers:

2

I ran into a strange issue with my indexed tableview's section index titles. The index titles returned is correct (A - Z) as outputted by the debugging code below but the displayed index titles on the right side of the table is separated with • instead. So instead of A B C D... I get A • C • E •... instead.

Any idea what's causing this? I have another tableview in my app but that tableview doesn't suffer from this problem but I haven't figured out why yet.

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

 NSMutableArray *sectionTitles = [[[NSMutableArray alloc] init] autorelease];
 [sectionTitles addObject:UITableViewIndexSearch];
 [sectionTitles addObjectsFromArray:[self.fetchedResultsController sectionIndexTitles]];

        // NSArray *debug = [self.fetchedResultsController sectionIndexTitles];
        // CFShow(debug);
 return sectionTitles;
}
+1  A: 

This is caused when the height available to display the index is less than what is needed to display each letter. The index is abbreviated (or shrunk). This effect will also occur when the keyboard is displayed and the index is still visible.

Mark
+1  A: 

I see you're adding the magnifying glass and using a NSFetchedResultsController. Did you figure out how to get the tableView to scroll to make the searchBar visible with the magnifying glass is touched? Returning 0 for tableView:sectionForSectionIndexTitle:atIndex: goes to the first section, e.g. "A", and the searchBar remains hidden. -1 doesn't work, either.

Edit: Nevermind, just found the solution elsewhere:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    NSMutableArray* indexTitles = [NSMutableArray arrayWithObject:UITableViewIndexSearch];  // add magnifying glass
    [indexTitles addObjectsFromArray:[self.fetchedResultsController sectionIndexTitles]];
    return indexTitles;
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
    if (title == UITableViewIndexSearch) {
     // if magnifying glass
        [self.resultsTable scrollRectToVisible:self.searchDisplayController.searchBar.frame animated:NO];
     return -1;
    }
    else
     return [self.fetchedResultsController sectionForSectionIndexTitle:title atIndex:index-1];
}
dk