Использовать значение индекса в строке раздела UITableView

#objective-c #xcode #uitableview #nsmutablearray #rows

#objective-c #xcode #uitableview #nsmutablearray #строки

Вопрос:

У меня есть два класса сущностей:

Module.h

 @interface Module : NSObject {

    NSString *moduleCode4;
    NSString *moduleTitle4;
    NSString *credits4;
    NSString *semester4;
    NSMutableArray *assessmentDetails4;
}
  

Подробная оценка.h

 @interface AssessmentDetail : NSObject {

    NSString *assessmentName4;
    NSString *assessmentType4;
    NSString *assessmentWeighting4;
    NSString *assessmentDueDate4;
}
  

Я заполнил классы внутри NSMutableArray.

В моем табличном представлении у меня есть:

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    GradeToolAppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
    return [appDelegate.modules4 count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    // The header for the section is the region name -- get this from the region at the section index.
    GradeToolAppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
    Module *aModule = [appDelegate.modules4 objectAtIndex:section];

    return [aModule moduleCode4];

}
  

Моя проблема в том, что мне нужен путь к строке индекса из индекса модуля раздела.

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    GradeToolAppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
    //Module *aModule = [appDelegate.modules4];
    AssessmentDetail *anAssess = [module.assessmentDetails4 objectAtIndex:section];
    return [anAssess count];
}
  

Я не могу понять, как получить количество оценок из раздела, кто-нибудь может мне здесь помочь.

Большое спасибо.

Ответ №1:

Большая его часть уже была в TableView:titleForHeaderInSection:

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   GradeToolAppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
   Module *aModule = [appDelegate.modules4 objectAtIndex:section];
   return [aModule.assessmentDetails4 count];
}