title: iOS tableview: Grouping rows into sections
body: <p>I'm displaying a dynamic list of names in a table view, and I'm trying to split them into sections according to the first letter of the name...</p>
  
  <p>I've created an array with an alphabetical list of letters</p>
  
  <pre><code>charIndex = [[NSMutableArray alloc] init];
  
  for(int i=0; i&lt;[appDelegate.children count]-1; i++)
  {
      // get the person
      Child *aChild = [appDelegate.children objectAtIndex:i];
  
      // get the first letter of the first name
      NSString *firstLetter = [aChild.firstName substringToIndex:1];
  
      NSLog(@"first letter: %@", firstLetter);
  
      // if the index doesn't contain the letter
      if(![charIndex containsObject:firstLetter])
      {
          // then add it to the index
          NSLog(@"adding: %@", firstLetter);
          [charIndex addObject:firstLetter];
      }
  }
  </code></pre>
  
  <p>and I've set up the number of sections and title</p>
  
  <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
      // set the number of sections in the table to match the number of first letters
      return [charIndex count];
  }
  
  - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  {
      // set the section title to the matching letter
      return [charIndex objectAtIndex:section];
  }
  </code></pre>
  
  <p>But I'm having trouble with what should be in</p>
  
  <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
  
  }
  </code></pre>