从UITableViewCell接收数据

时间:2011-05-23 00:37:29

标签: objective-c xcode uitableview custom-cell

我有以下代码集:

- (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];

}

感谢您的帮助。

1 个答案:

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