0

我有以下代码集:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"customCell";

    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nibObjs = [[NSBundle mainBundle] loadNibNamed:@"CustomCellView" owner:nil options:nil];
        //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        for(id currentObj in nibObjs)
        {
            if([currentObj isKindOfClass:[CustomCell class]])
            {
                cell = (CustomCell *)currentObj;
            }

        }
    }

    AssessmentDetail * anAssess = [module.assessmentDetails4 objectAtIndex:indexPath.row];
    [[cell labelAssessment] setText:anAssess.assessmentName4];
    return cell;
}

在我的自定义单元格中有一个UISlider. 我想做的是使用一个按钮从每一行中检索每个 UISlider 的值,这样我就可以获得一个总值。

我想过这样做,但我不确定从那里去哪里:

- (IBAction) calculateTotal:(id)sender {

    static NSString *CellIdentifier = @"customCell";

    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

}

谢谢您的帮助。

4

1 回答 1

1

循环浏览 UITableView 的子视图:

- (IBAction) calculateTotal:(id)sender {
    NSArray *subViews = [myTableView subviews];
    float total;

    for (int i = 0; i < subViews.count; i++)
    {
         id obj = [subViews objectAtIndex:i];
         if ([obj isKindOfClass:[CustomCell class]])
         {
              total += [[obj getMySlider] getValue];
         }
    }

    // do something with total
}
于 2011-05-23T01:13:34.550 回答