2

我在使用自定义单元格的 UITableView 中控制 UIStepper 时遇到问题。当我在 (row=0) 中使用 stepper 更改一个 UITextField.text 时,它工作正常,问题是 row=9 中的文本字段也发生了变化。row=1 和 row=10 等也会发生同样的情况。我真的不明白为什么。

tableviewcontroller中stepper的IBAction代码:

- (IBAction)sumaRestaNormal:(id)sender {
// Get the cell in which the button was pressed
celdaTabacoNormal *cell = (celdaTabacoNormal *)[[[sender superview] superview]superview];
// Get the value of the stepper (it has an outlet in my custom cell
int value = cell.stepperNormal.value;
// Update the text field of the cell with the new value (also has an outlet in the custom cell)
cell.txtNormal.text = [NSString stringWithFormat:@"%d",value];}

UITextFields 是 customcell.h 中的属性:

@property (weak, nonatomic) IBOutlet UITextField *txtNormal;

在 cellForRowAtIndexPath 我有下一个:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    celdaTabacoNormal *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if(!cell){
        cell = [[celdaTabacoNormal alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.referenciaTabacoN.text = [arrayRefTabaco objectAtIndex:indexPath.row];
    NSString * marcaNombre = [NSString stringWithFormat:@"%@ - %@", [arrayMarcaTabaco objectAtIndex:indexPath.row], [arrayNomTabaco objectAtIndex:indexPath.row]];
    cell.nombreProductoN.text = marcaNombre;

    return cell;
}

为什么第 0 行和第 9 行的 UITextFields 等会同时发生变化......!

在这里,我展示了细胞是如何的:

http://www.imagesup.net/?di=5140982874911

问题来自细胞的重用。我应该如何使用步进器和文本字段来控制这种类型的单元格?

4

0 回答 0