0

ステッパーとラベルが付いたカスタムテーブルビューセルを使用しています。しかし、ステッパーの値を確認すると、2回押すごとに1回だけ増加します。何が問題ですか?

- (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 に答える