0

我正在使用带有步进器和标签的自定义表格视图单元格。但是当我检查步进器的值时,它每 2 次按下只会增加一次。问题是什么?

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

1 回答 1

0

尝试将此添加到您的 valueChanged 方法中:

[self.myTableView beginUpdates];
[self.myTableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:NO];
[self.myTableView endUpdates];
于 2012-08-22T06:48:14.137 回答