title: UITableView - Alphabet
body: <p>Here is the improvement that I wish to add to my UITableView with alphabet:</p>
  
  <p>If there are no results in my table that don't start with one of the letters of the alphabet, I don't want to see this titleForHeaderInSection in my UITableView.</p>
  
  <p>And I don't find the way to do that.</p>
  
  <p>You can see my current implementation and an image as example (<a href="http://blog.joefusco.name/wp-content/uploads/2010/10/indexed-table.jpg" rel="nofollow">http://blog.joefusco.name/wp-content/uploads/2010/10/indexed-table.jpg</a>):</p>
  
  <p>facilitiesViewController.h:</p>
  
  <pre><code>@interface FacilitiesViewController : UITableViewController &lt;UITableViewDelegate, UITableViewDataSource, ...&gt;  {
               IBOutlet UITableView     *facilitiesTableView;
               NSMutableArray           *facilitiesDictionary;
               NSArray                  *alphabet;
               ...
  }
  @property (nonatomic, retain)     NSMutableArray     *facilitiesDictionary;
  @property (nonatomic, retain)     NSArray          *alphabet;
  ...
  
  @end
  </code></pre>
  
  <p>facilitiesViewController.m:</p>
  
  <pre><code>@implementation FacilitiesViewController
  ...
  
  - (void)viewDidLoad {
       [super viewDidLoad];
  
       alphabet = [[NSArray alloc]initWithObjects:@"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];
  
       facilitiesDictionary = [[NSMutableArray alloc]init];
  
       for (int i = 0; i &lt; [alphabet count]; i++)
            [facilitiesDictionary insertObject:[[NSMutableArray alloc] init] atIndex: i];
       ... }
  
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
          return [alphabet count]; }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       return [[facilitiesDictionary objectAtIndex:section] count]; }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
          ...     
          return cell; }
  
  - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
       return alphabet; }
  
  - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
          return [alphabet indexOfObject:title]; }
  
  - (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section {
       return [alphabet objectAtIndex:section]; }
  
  @end
  </code></pre>