Sekcje UITableView systemu iOS z pomyłką fetchedResultsController

Mam obiekt wyświetlany w widoku tabeli w jednej sekcji. Jednostka ma dwa atrybuty,workoutName itrainingLevel. Oba są typu string. Poziom szkolenia składa się z 3 typów: 1, 2, 3. (trainingLevel = (Integer 16 lub String Type? Co byłoby idealne?) Chciałbym podzielić tabelę na trzy sekcje, każda sekcja zawierająca wpisy dla odpowiedniego poziomu szkolenia .

Jak mam to zrobic? Kod, którego aktualnie używam, jest poniżej:

- (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:&error])
    {
        NSLog(@"Fetch failed: %@", error);
    }
}

To, z czym walczę to:

Jak określić liczbę wierszy dla każdej sekcji poprzez podstawowy model danych, pobierając liczbę wpisów z poziomem szkolenia 1 lub 2 lub 3.Jak wypełnić wiersze każdej sekcji, pobierając odpowiednie elementy.Jak nadać tytuł nagłówkowi każdej sekcji.

questionAnswers(1)

yourAnswerToTheQuestion