views:

39

answers:

0

ok, so I have custom cells with UISegmentedControl and UILabel

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

static NSString *MyIdentifier = @"testCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"testCell" owner:self options:nil];
    cell = testCell;
    self.testCell = nil;
}
cellLabel = (VerticallyAlignedLabel *)[cell viewWithTag:11];
cellLabel.text = [array objectAtIndex:indexPath.section];
cellControl = (UISegmentedControl *)[cell viewWithTag:22];
return cell;

So it is some sort of test: in the label I have questions, SegmentedControl is handling answers. Every segment should assign integer value to "int segmentValue"

Obviously there should be some calculations - segmentValue handled by method segmentValuePicked

-(IBAction) segmentValuePicked {
    switch (self.cellControl.selectedSegmentIndex) {
        case 0:
            segmentValue = 0;
            break;
        case 1:
            segmentValue = 2;
            break;
        case 2:
            segmentValue = 4;
            break;
        case 3:
            segmentValue = 6;
            break;
        case 4:
            segmentValue = 8;
            break;
        case 5:
            segmentValue = 10;
            break;
        default:
            break;
    }

}

The problem is that I don't know where to go further, and especially where to manage all the calculations and how. I figured out that it has to be outside of cellForRowAtIndexPath: because after segment value has changed the cell should be reloaded. So how to do it and where - in ViewDidLoad or in delegate methods?

Secondly, people choice should be limited in a way where sum of all cells won't exceed 10, so every instance of UISegmentedControl has to depend on each other and that means "switch" or "if" statement should be inside cellForRowAtIndexPath:, right?

Finally, I guess I need an array of segmentValue (because I have 7 cells and 7 Segmented Controls) instead of just one integer, but don't know how to initialize it.

So I totally confused.

Please push me in some direction. Thanks in advance.