title: ios core data to AZ indexed tableview
body: <p>I'm trying to show the values of my core data model to an A-Z indexed table based on the first letter on my attributes (similar to the iOS address book app). The "Favorites" entity of my core data model has 2 attributes: username and status. I want to display only the usernames with <code>status = accepted</code> to the A-Z indexed table.
  Here is my code:</p>
  
  <pre><code>- (NSFetchedResultsController *)fetchedResultsController {
  
  if (fetchedResultsController != nil) {
      return fetchedResultsController;
  }
  
  NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
  
  NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
  NSEntityDescription *entity = [NSEntityDescription entityForName:@"Favorites" inManagedObjectContext:managedObjectContext];
  [fetchRequest setEntity:entity];
  
  NSString *status = @"accepted";
  NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status == %@",status];
  [fetchRequest setPredicate:predicate];
  
  // Create the sort descriptors array.
  NSSortDescriptor *usernameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"username" ascending:YES];
  NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:usernameDescriptor, nil];
  [fetchRequest setSortDescriptors:sortDescriptors];
  
  // Create and initialize the fetch results controller.
  NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"username" cacheName:@"Root"];
  self.fetchedResultsController = aFetchedResultsController;
  fetchedResultsController.delegate = self;
  
  return fetchedResultsController;
  }
  </code></pre>
  
  <p>Now when I'm trying to access the section name I get (null) </p>
  
  <pre><code>-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
   {
       NSLog(@"%@",[[[fetchedResultsController sections] objectAtIndex:section] name]);
       return [[[fetchedResultsController sections] objectAtIndex:section] name];
   }
  </code></pre>
  
  <p>Also I thing that with that way I will get the the name and not the first char in order to display it as a section title.</p>