title: iOS UITableView sections with fetchedResultsController confusion
body: <p>I have an entity being displayed in a table view in just one section. The entity has two attributes, <code>workoutName</code> and <code>trainingLevel</code>. Both are of string type. Training level consists of the 3 types: 1, 2, 3. (trainingLevel = (Integer 16 or String Type? Which would be ideal?) I would like to split the table into three sections, each section containing entries for the corresponding training level.</p>
  
  <p>How do I do this? The code I am currently using is below:</p>
  
  <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
  // Return the number of sections.
      return 1;
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      // Return the number of rows in the section.
      return self.workoutType.workouts.count;
  }
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"Cell";
      UITableViewCell *cell =
      [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil)
      {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                    reuseIdentifier:CellIdentifier];
          cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
      }
  
  
      WorkoutSet *workoutSet = [self.fetchedResultsController objectAtIndexPath:indexPath];
  
  
      cell.textLabel.text = workoutSet.workoutName;
      cell.detailTextLabel.text = [NSString stringWithFormat:@"(%d)", workoutSet.days.count];    
  }
  
  -(void)fetchWorkoutSets
  {
  
      NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"WorkoutSet"];
      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"workoutType = %@", self.workoutType];
  
      NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"workoutName" ascending:YES];
      [fetchRequest setSortDescriptors:@[sortDescriptor]];
      [fetchRequest setPredicate:predicate];
      self.fetchedResultsController = [[NSFetchedResultsController alloc]
                                   initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext
                                   sectionNameKeyPath:nil cacheName:nil];
  
      NSError *error;
      if (![self.fetchedResultsController performFetch:&amp;error])
      {
          NSLog(@"Fetch failed: %@", error);
      }
  }
  </code></pre>
  
  <p>What I am struggling with is:</p>
  
  <ul>
  <li>How to determine the number of rows for each section through the core data model by fetching number of entries with training level 1 or 2 or 3.</li>
  <li>How to fill the rows of each section by fetching the correct items.</li>
  <li>How to give a title to each section header.</li>
  </ul>