因未捕获的异常'NSGenericException'而终止应用程序,原因:'*** Collection <calayerarray:0x17485f7a0 =“”>在枚举时发生了变异

时间:2017-04-25 11:14:48

标签: ios objective-c for-loop nsarray block

  

将数据添加到可变数组并计算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];

0 个答案:

没有答案
相关问题