您好,我曾尝试使用 for 循环用两个 NSMutableArray 数据填充 NSMutableDictionary,当循环完成时,NSMutableDictionary 只显示加载的最后一个值,有什么问题吗?按照代码
-(void)calculateDistance
{
self.distanceArray=[[NSMutableArray alloc]init];
self.dict=[[NSMutableDictionary alloc]init];
for (int i=0; i<[self.nombre count]; i++) {
CLLocation *shopPosition=[[CLLocation alloc]initWithLatitude:[[self.latitud objectAtIndex:i] floatValue]longitude:[[self.longitud objectAtIndex:i]floatValue]];
self.userPosition=[[CLLocation alloc]initWithLatitude:self.currentLat longitude:self.currentLong];
self.distance=[shopPosition distanceFromLocation:self.userPosition];
[self.distanceArray addObject:[NSNumber numberWithFloat:self.distance]];
[self.dict setObject:[self.distanceArray objectAtIndex:i] forKey:@"distance"];
[self.dict setObject:[self.nombre objectAtIndex:i] forKey:@"nombre"];
}
NSLog(@" DICT %@",self.dict);
非常感谢