将数据添加到可变数组并计算lat和long的距离并将其添加到我的数组中,我认为在将数据从服务器添加到我的可变数组时可能会枚举循环。提前谢谢
NSArray *arr;
NSMutableArray * mapViewDataArrayNew = [[NSMutableArray alloc]init];
mSaveDataArr=[[NSMutableArray alloc]init];
self.barsDataArray=[[NSMutableArray alloc]init];
arr = [responseData[kData] mutableCopy];
Distancearr =[DRMapView initializeValue];
for(int ii =0;ii<[arr count];ii++)
{
NSMutableDictionary * object =arr[ii];
mMapViewObj = [[DRMapView alloc]init];
[mMapViewObj setUpData:object :ii+1];
[object setObject:mMapViewObj.mDistance forKey:kDistance];
[mSaveDataArr addObject:object];
[mapViewDataArrayNew addObject:mMapViewObj];
}
//Sort array
NSSortDescriptor *sortByName =[NSSortDescriptor sortDescriptorWithKey:kDistance ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortByName];
NSArray *sortedArray = [Distancearr sortedArrayUsingDescriptors:sortDescriptors];
Distancearr=nil;
Distancearr=sortedArray;
NSOrderedSet *orderedSet = [NSOrderedSet orderedSetWithArray:Distancearr];
Distancearr=nil;
Distancearr = [orderedSet array];
for(NSMutableDictionary *dict in Distancearr)
{
NSNumber *dist = [dict objectForKey:kDistance];
for(DRMapView * mapObj in mapViewDataArrayNew)
{
if([mapObj.mDistance isEqualToNumber:dist])
{
[self.barsDataArray addObject:mapObj];
}
}
}
//Reload table view
distanceLbl.text=[NSString stringWithFormat:@"Maximum distance limit %@ Km",[HelperUDLib getObject:@"barRange"]];
[UIView transitionWithView:listView
duration:1.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^(void) {
[weakSelf.barsListTableView reloadData];
distanceLbl.text=[NSString stringWithFormat:@"Maximum distance limit 200 Km"];
}
completion:nil];