【发布时间】:2017-06-15 13:09:18
【问题描述】:
在我的代码中,我有多个位置,我必须检查所有位置是否正确(使用 google api 检查)如果位置正确,我必须获取该位置的坐标。
我正在尝试在 for 循环中编写代码,有什么方法可以等待 for 循环中的响应。
我在下面粘贴我的代码。
提前致谢。
for (int locationsCount=0;locationsCount<results.count;locationsCount++)
{
NSString *googlelocations = [[results objectAtIndex:locationsCount]objectForKey:@"description"];
if ([locationAddress isEqualToString:googlelocations])
{
[[LocationManager share] fetchLatLngForPlacename:googlelocations placeId:[[results objectAtIndex:locationsCount] objectForKey:@"place_id"] completion:^(double lat, double lng, NSError *error)
{
[SVProgressHUD dismiss];
if (error) {
}else {
CLLocation *locationCoordinates = [[CLLocation alloc]initWithLatitude:lat longitude:lng];
NSMutableArray *globalArray = [[LocationManager share]getManualInterLocationArray];
NSMutableDictionary *dict = [[globalArray objectAtIndex:selectedTextField.tag] mutableCopy];
[dict setObject:locationCoordinates forKey:@"location_coordinates"];
[dict setObject:googlelocations forKey:@"location_Address"];
[dict setObject:[NSNumber numberWithBool:true] forKey:@"manualEntry_Flag"];
[globalArray replaceObjectAtIndex:selectedTextField.tag withObject:dict];
[[LocationManager share]saveManualInterLocationArray:globalArray];
}
}];
}
}
【问题讨论】:
标签: ios objective-c xcode objective-c-blocks