我想將浮點變量賦值給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循環中計算的每個距離。 –
我很樂意提供幫助,但需要查看迄今爲止編寫的代碼。編輯您的原始問題,將更新後的代碼放在當前代碼下。 - 我會看到我能看到的。 –