问题描述
我正在动态创建文本字段并对其进行加减...
i am creating the textfield dynamically and adding and subtracting them...
如何在同一循环中从两个不同数组中计算并选择值?
How to calculate and pick the value from two diffrent array on a same loop?
类似的东西
例如:for(UITextField * textFieldArray&& textFieldArray2中的字段)
eg: for(UITextField *field in textFieldArray && textFieldArray2)
我必须减去该值,并且我有2个数组,我想从不同数组但相同索引中减去两个文本字段的值...
i have to subtract the value and i have 2 Array and i want to subtract the value of two textfield from different array but same index...
我的代码是
int result = 0;
for(UITextField *field in textFieldArray) // will iterate all UITextField which was added
{
result += [field.text intValue]; //or floatValue
}
NSLog(@"the result is %d", result); //here you have sum of all the text fields' text
我想减去这个值,但是两个文本字段都在不同的数组上,但是具有相同的索引...
i want to subtract this but both text fields are on different Array but have same index...
int y12=([Txt_New_Actual.text intValue]);
float c116= y12-([Txt_New_Estimated.text floatValue]);
Txt_New_ONU.text = [[NSString alloc] initWithFormat:@"%.2f",c116];
推荐答案
您可以这样做.取一个变量进行相同的迭代
You could do it this way. Take one variable to iterate in common as
UITextField *fieldArray1=nil,*fieldArray2=nil;
for(int i =0;i<textFieldArray1.count;i++)
{
fieldArray1 = [textFieldArray1 objectAtIndex:i]; //This is field in array1
fieldArray2 = [textFieldArray2 objectAtIndex:i]; //This is field in array2 and both are at same index.
//Do your operation here...
}
这篇关于创建到NSMutableArray时动态计算TextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!