在我的代码我有多个位置,我必须检查所有的位置是否正确(检查与谷歌API)如果位置是正确的我必须得到该位置的坐标。如何等待for循环(Xcode,Objective C,iOS)中的callBack方法(或)响应?
我想在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];
}
}];
}
}
我想要的方式进行回调。可能吗? –
是的! A编辑了答案 – iamirzhan
上述方法被回调函数调用,所以完成该过程后我们必须发送确认才能继续下一个过程。如果(appDelegate()。internetSatus == false){ return;}(void)(void } addressArrayCount = 0; (自动地址验证:地址数组和计数完成:^(BOOL isSuccess) { if(isSuccess){callBack(true); NSLog(@“completed”); } }]; } –