在行部分UITableView中使用索引值

时间:2011-05-22 21:50:27

标签: objective-c xcode uitableview nsmutablearray rows

我有两个实体类:

module.h中

@interface Module : NSObject {

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

AssessmentDetail.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 个答案:

答案 0 :(得分: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];
}