我在单元格中有4个文本字段。当我在其中一些中输入值时,我将调用一个方法,然后需要在另一个文本字段中显示一些数据。我有3排细胞。目前只有最后一行的值才能正确显示。
{
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.qntityTxt.tag=indexPath.row;
[cell.qntityTxt addTarget:self action:@selector(totalCalc:) forControlEvents:UIControlEventEditingDidEnd];
return cell;
}
- (void)totalCalc:(UITextField*)txtfield
{
int total,price,qty;
NSLog(@"Tag value %ld",(long)txtfield.tag);
price=[cell.priceTxt.text intValue];
qty=[cell.qntityTxt.text intValue];
total=price*qty;
Total=[NSString stringWithFormat:@"%d",total];
cell.totlTxt.text=Total;
[_addPdtTblVw reloadData];
}
[![enter image description here][1]][1]
答案 0 :(得分:0)
这与你的评论相同!!
(void)totalCalc:(UITextField*)txtfield {
int total,price,qty;
NSLog(@"Tag value %ld",(long)txtfield.tag);
for (int i=0; i < 3; i++){
NSIndexPath indexPath = [NSIndexPath indexPathForRow: i inSection: 0];
cell = [_addPdtTblVw cellForRowAtIndexPath:indexPath];
UITextField *TextProduct= (UITextField)[cell.contentView viewWithTag:8];
UITextField *TextPrice= (UITextField)[cell.contentView viewWithTag:9];
UITextField *TextQuantity= (UITextField)[cell.contentView viewWithTag:10];
UITextField *TextTotal= (UITextField)[cell.contentView viewWithTag:11];
price=[TextPrice.text intValue];
qty=[TextQuantity.text intValue];
total=price*qty;
Total=[NSString stringWithFormat:@"%d",total];
cell.totlTxt.text=Total;
}
[_addPdtTblVw reloadData];
}