我想将浮点变量赋值给for循环中的nsmutable数组。我在下面做了。但是nsmutable数组似乎是空的。我该如何解决这个问题? (距离为float,并且enyakinarray是NSMutableArray的。)将浮点值分配给NSMutableArray
for (int i=0; i<[ws3.CustomerID count]; i++) {
//radian hesaplaması
float total = [first floatValue];
float theta = total * M_PI/180;
float total2 = [second floatValue];
float theta2 = total2 * M_PI/180;
float total3 = [[ws3.Latitude objectAtIndex: i] floatValue];
float theta3 = total3 * M_PI/180;
float total4 = [[ws3.Longitude objectAtIndex: i] floatValue];
float theta4 = total4 * M_PI/180;
distance = 6371 * acos(cos(theta) * cos(theta3)
* cos(theta4 - theta2)
+ sin(theta) * sin(theta3)) ;
NSLog(@"xxxxx %f",distance);
num = [NSNumber numberWithFloat:distance];
enyakinarray = [[NSMutableArray alloc] init];
[enyakinarray addObject:num];
NSLog(@"asasasas %@",enyakinarray);
}
好吧,当我分配enyakinarray,它每次都会改变。分配过程在for循环中。我想这样做:重复循环,直到计算另一个数组的数量和距离,并将距离添加到enyakinarray。 –
我想保留在enyakinarray for循环中计算的每个距离。 –
我很乐意提供帮助,但需要查看迄今为止编写的代码。编辑您的原始问题,将更新后的代码放在当前代码下。 - 我会看到我能看到的。 –