0

I'm using a custom table view cell with a stepper and a label. But when i check the value of the stepper it increases only once for every 2 presses. What is the problem?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cellData";
    ItemCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil)
    {
        cell = [[ItemCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.stepper.tag = indexPath.row;
    cell.countLabel.text = [NSString stringWithFormat:@"%g",cell.stepper.value];
    NSLog(@"value = %g",cell.stepper.value);
    cell.itemLabel.text = [self.groceryItems objectAtIndex:indexPath.row];
    return cell;
}

- (IBAction)valueChanged:(id)sender
{
    UIStepper *step = sender;
    NSIndexPath *index = [NSIndexPath indexPathForRow:step.tag inSection:0];
    NSArray *rowsToReload = [NSArray arrayWithObject:index];
    [self.myTableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:NO];
}
vivek241
  • 666
  • 1
  • 7
  • 18

1 Answers1

0

try to add this to your valueChanged Method:

[self.myTableView beginUpdates];
[self.myTableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:NO];
[self.myTableView endUpdates];
nooitaf
  • 1,466
  • 11
  • 18