Ios 从表视图单元格中的UITextfield获取和设置值
我在单元格中有4个文本字段。当我在其中一些字段中输入值时,我将调用一个方法,然后需要在另一个文本字段中显示一些数据。我有3行单元格。目前只有最后一行的值正确Ios 从表视图单元格中的UITextfield获取和设置值,ios,objective-c,uitableview,cocoa-touch,uitextfield,Ios,Objective C,Uitableview,Cocoa Touch,Uitextfield,我在单元格中有4个文本字段。当我在其中一些字段中输入值时,我将调用一个方法,然后需要在另一个文本字段中显示一些数据。我有3行单元格。目前只有最后一行的值正确 { cell.selectionStyle=UITableViewCellSelectionStyleNone; cell.qntityTxt.tag=indexPath.row; [cell.qntityTxt addTarget:self action:@selector(t
{
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]
这和你的评论是一样的
(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];
}
(void)totalCalc:(UITextField*)txtfield{
整数总计、价格、数量;
NSLog(@“标记值%ld”,(长)txtfield.Tag);
对于(int i=0;i<3;i++){
NSIndexPath indexPath=[NSIndexPath indexPathForRow:i第1节:0];
cell=[\u addPdtTblVw cellforrowatinexpath:indexPath];
UITextField*TextProduct=(UITextField)[cell.contentView视图带标记:8];
UITextField*TextPrice=(UITextField)[cell.contentView viewWithTag:9];
UITextField*TextQuantity=(UITextField)[cell.contentView viewWithTag:10];
UITextField*TextTotal=(UITextField)[cell.contentView viewWithTag:11];
价格=[TextPrice.text intValue];
数量=[TextQuantity.text intValue];
总价=价格*数量;
总计=[NSString stringWithFormat:@“%d”,总计];
cell.totlText.text=总计;
}
[_addpdttblvwreloaddata];
}
totalcalc方法中的单元格是如何获得的?我得到了解决方案-(void)totalcalc:(UITextField*)txtfield{int total,price,qty;NSLog(@“Tag value%ld”,(long)txtfield.Tag);for(int I=0;I<3;I++){nsindexath indexPath=[NSIndexPath indexPathForRow:I安全设置:0];单元格=[u addPdtTblVw cellForRowAtIndexPath:indexPath];UITextField*TextProduct=(UITextField)[cell.contentView视图带标记:8];UITextField TextPrice=(UITextField)[cell.contentView视图带标记:9];UITextField TextQuantity=(UITextField)[cell.contentView视图带标记:10];UITextField TextTotal=(UITextField)[cell.contentView视图带标记: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];总计=价格*数量;总计=[NSString stringWithFormat:@“%d”,总计];cell.totlText.text=总计;}[\u addPdtTblVw reloadData];}@lj999请不要在评论中发布代码。如果您有更多详细信息要添加,请发布您的问题;如果您解决了自己的问题,请发布实际答案。由于未捕获的异常“NSInvalidArgumentException”,我收到此异常终止应用程序,原因:'-[UIView priceTxt]:无法识别的选择器发送到实例0x7fb862d0d9e0'你是否得到解决方案??你在评论中写了一些东西!!是的,我自己找到了解决方案。当我输入你的代码时,它给出了一个例外你想要我的解决方案吗?你的愿望:)是的,我知道..等等!正在处理它!你想更新所有单元格的所有文本字段吗??