Sandeep Bansal
Sandeep Bansal

Reputation: 6404

Receive Data from UITableViewCell

I have the following code set:

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

In my custom cell there is a UISlider. What I would like to do is use a button to retrieve the value of each UISlider from each row so I can get a total value.

I thought about doing this but I'm not certain on where to go from there:

- (IBAction) calculateTotal:(id)sender {

    static NSString *CellIdentifier = @"customCell";

    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

}

Thanks for the help.

Upvotes: 0

Views: 134

Answers (1)

Richard J. Ross III
Richard J. Ross III

Reputation: 55593

Cycle through the subviews of the 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
}

Upvotes: 1

Related Questions