Iphone 如何将元素添加到由';对于';环
我使用for循环获取从当前位置到目标位置的距离。我想要一个数组,它包含从当前位置到目标位置的所有距离Iphone 如何将元素添加到由';对于';环,iphone,Iphone,我使用for循环获取从当前位置到目标位置的距离。我想要一个数组,它包含从当前位置到目标位置的所有距离 for (i = 0; i < [Arr_Lat count]; i++) { NSString *latst1 = [[NSString alloc]initWithFormat:[Arr_Lat objectAtIndex:i]]; NSString *longst1 = [[NSString alloc]initWithFormat:[Arr_Long objec
for (i = 0; i < [Arr_Lat count]; i++)
{
NSString *latst1 = [[NSString alloc]initWithFormat:[Arr_Lat objectAtIndex:i]];
NSString *longst1 = [[NSString alloc]initWithFormat:[Arr_Long objectAtIndex:i]];
NSLog(@"First lat : %@",latst1);
NSLog(@"First ong : %@",longst1);
double Doblat1 = [latst1 doubleValue];
double Doblong1 = [longst1 doubleValue];
CLLocationCoordinate2D coord1 = CLLocationCoordinate2DMake(coord1.latitude = Doblat1, coord1.longitude = Doblat1);
NSLog(@" Coordinat ==== : %f -- %f",coord1.latitude,coord1.longitude) ;
CLLocation *currLoc = [[CLLocation alloc] initWithLatitude:appDel.curr_lat longitude:appDel.curr_long];
CLLocation *destLoc1 = [[CLLocation alloc] initWithLatitude:Doblat1 longitude:Doblong1];
NSLog(@" Currennt Location : %@", currLoc);
NSLog(@" Destination Location : %@" , destLoc1);
distance = [destLoc1 distanceFromLocation:currLoc];
NSLog(@" Distance : ------- %0.3f", distance);
DistStr = [[NSString alloc]initWithFormat:@" %f",distance];
[currLoc release];
[destLoc1 release];
[Arr_title retain];
[tbl_nearplace reloadData];
}
for(i=0;i<[Arr_Lat count];i++)
{
NSString*latst1=[[NSString alloc]initWithFormat:[Arr_Lat objectAtIndex:i]];
NSString*LONGT1=[[NSString alloc]initWithFormat:[Arr_Long objectAtIndex:i]];
NSLog(@“第一个lat:%@”,latst1);
NSLog(@“第一个ong:%@”,longt1);
double-Doblat1=[latst1-doubleValue];
double Doblong1=[longst1 doubleValue];
CLLocationCoordinate2D coord1=CLLocationCoordinate2DMake(coord1.纬度=Doblat1,coord1.经度=Doblat1);
NSLog(@“坐标==:%f--%f”,坐标1.纬度,坐标1.经度);
CLLocation*currLoc=[[CLLocation alloc]initWithLatitude:appDel.curr_lat经度:appDel.curr_long];
CLLocation*destLoc1=[[CLLocation alloc]INITWITH纬度:Doblat1经度:Doblong1];
NSLog(@“当前位置:%@”,currLoc);
NSLog(@“目的地位置:%@”,目的地1);
距离=[destLoc1 distanceFromLocation:currLoc];
NSLog(@“距离:---%0.3f”,距离);
DistStr=[[NSString alloc]initWithFormat:@“%f”,距离];
[货币发行];
[destLoc1释放];
[保留所有权];
[tbl_近地点重新加载数据];
}
如果要存储距离,则需要NSMutableArray
NSMutableArray*distanceArray代码>在类范围内
DistStr=[[NSString alloc]initWithFormat:@“%f”,distance]之后的for循环中代码>
编写以下代码:
[distanceArray addObject:DistStr];
NSMutableArray*Distance=[[NSMutableArray alloc]Init];
对于(i=0;i<[Arr_Lat count];i++)
{
NSString*latst1=[[NSString alloc]initWithFormat:[Arr_Lat objectAtIndex:i]];
NSString*LONGT1=[[NSString alloc]initWithFormat:[Arr_Long objectAtIndex:i]];
NSLog(@“第一个lat:%@”,latst1);
NSLog(@“第一个ong:%@”,longt1);
double-Doblat1=[latst1-doubleValue];
double Doblong1=[longst1 doubleValue];
CLLocationCoordinate2D coord1=CLLocationCoordinate2DMake(coord1.纬度=Doblat1,coord1.经度=Doblat1);
NSLog(@“坐标==:%f--%f”,坐标1.纬度,坐标1.经度);
CLLocation*currLoc=[[CLLocation alloc]initWithLatitude:appDel.curr_lat经度:appDel.curr_long];
CLLocation*destLoc1=[[CLLocation alloc]INITWITH纬度:Doblat1经度:Doblong1];
NSLog(@“当前位置:%@”,currLoc);
NSLog(@“目的地位置:%@”,目的地1);
距离=[destLoc1 distanceFromLocation:currLoc];
NSLog(@“距离:---%0.3f”,距离);
NSString*DistStr=[[NSString alloc]initWithFormat:@“%f”,距离];
[Distance addObject:DistStr];
[DistStr释放];
[货币发行];
[destLoc1释放];
[保留所有权];
[tbl_近地点重新加载数据];
}
假设我们有一个数组,其中包含要迭代的内容,并将这些内容添加到另一个数组中
NSArray *someArrayWithStuff = @[@"Hello",
@"Its",
@"Very",
@"Cold",
@"Outside",
@"Today"];
假设我们希望将someArrayWithStuff的内容添加到另一个数组中,因此我们创建了一个NSMutableArray
NSMutableArray *theNewArrayWithOurStuff = [NSMutableArray array];
我们在有东西的阵列中循环
for (int i = 0; i < someArrayWithStuff.count; i++) {
// Add object to the new array
[theNewArrayWithOurStuff addObject:[someArrayWithStuff objectAtIndex:i]];
}
for(int i=0;i
for (int i = 0; i < someArrayWithStuff.count; i++) {
// Add object to the new array
[theNewArrayWithOurStuff addObject:[someArrayWithStuff objectAtIndex:i]];
}