I have a problem controlling UIStepper in a UITableView with custom cell. When I change one UITextField.text with stepper in (row=0) it works fine, the problem is the textfield in the row=9 change too. The same happen with row=1 and row=10, etc. I really don't get why.
The code of IBAction of the stepper in the tableviewcontroller:
- (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];}
The UITextFields are properties in the customcell.h:
@property (weak, nonatomic) IBOutlet UITextField *txtNormal;
In the cellForRowAtIndexPath I have the next:
- (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;
}
Why the UITextFields from row 0 and row 9, etc change at same time...!
Here I show how the cells are:
http://www.imagesup.net/?di=5140982874911
The problem comes from the reuse of cells. How should I do for controlling this type of cells with steppers and textfields?