【发布时间】:2017-08-01 22:13:22
【问题描述】:
我在单元格中有 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]
【问题讨论】:
-
你是如何在 totalcalc 方法中得到单元格的?
-
我得到了解决方案 - (void)totalCalc:(UITextField*)txtfield { int total,price,qty; NSLog(@"标签值 %ld",(long)txtfield.tag); for (int i=0; i indexPath = [NSIndexPath indexPathForRow: i inSection: 0];单元格 = [_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]; NSLog(@"TextProduct mthd :%@",TextProduct.text); NSLog(@"TextPrice mthd :%@",TextPrice.text); NSLog(@"TextQuantity :%@",TextQuantity.text); NSLog(@"TextTotal mthd :%@",TextTotal.text);价格=[TextPrice.text intValue];数量=[TextQuantity.text intValue];总计=价格*数量;
-
Total=[NSString stringWithFormat:@"%d",total]; cell.totlTxt.text=总计; } [_addPdtTblVw reloadData]; }
-
@lj999 请不要在 cmets 中发布代码。 edit您的问题,如果您有更多详细信息要添加或发布实际答案,如果您解决了自己的问题。
标签: ios objective-c uitableview cocoa-touch uitextfield