title: Indexed UITableView, like Contacts.app
body: <p>I want to replicate Contacts.app's scrollbar behavior.</p>
  
  <p>I know that you must implement those two methods :</p>
  
  <pre><code>- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
  - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
  </code></pre>
  
  <p>And that what I've done : the first one returns an array of characters for A to Z, and the second one returns the index.
  So far, it works quite well : I got the scrollbar, and scrolling on it makes the UITableView scroll.</p>
  
  <p>But I have two questions :</p>
  
  <p>First,the problem is, if I don't have contacts for the letter C for example, then the scrolling will obviously be staggered, and scrolling on C will show the D index, scrolling on D will show the E index...
  I though about searching the closest section, but is that the most efficient way to do it ?
  Something like implementing this function in my class :</p>
  
  <pre><code>- (NSInteger) getSectionIndexForSectionTitle:(NSString *section) {
      if ([_allSections objectForKey:section] == nil) {
          NSComparisonResult res = NSOrderedAscending;
          for (NSString* sectionTitle in _allSections) {
              NSComparisonResult tmp = [sectionTitle compare:section]; 
              if (tmp == NSOrderedDescending &amp;&amp; res == NSOrderedAscending)
                  return [(NSNumber *)[_allSections objectForKey:sectionTitle] intValue];
              res = tmp;
          }
          return [_allSections count] - 1;
      }
      return [(NSNumber *)[_allSections objectForKey:section] intValue];
  }
  </code></pre>
  
  <p>But I'm afraid of the poor performances that this solutions might provide.</p>
  
  <p>Second question, that might be linked with the first one : In the Contacts.app, you can't see the "O" letter in the scrollbar, but you can still scroll to this section.
  Any idea on how to achieve that ?</p>
  
  <p>Thanks for reading and helping me !</p>