gpt4 book ai didi

iphone - 尝试调用 reverseGeocodeLocation,但程序一直跳过函数调用。有任何想法吗?

转载 作者:行者123 更新时间:2023-11-29 13:26:25 26 4
gpt4 key购买 nike

这是我的代码和我尝试调用 reverseGeocodeLocation 的完整上下文:

CLLocationCoordinate2D touchMapCoordinate = 
[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];

CLLocation *destination = [[CLLocation alloc] initWithLatitude:touchMapCoordinate.latitude longitude:touchMapCoordinate.longitude];

__block CLGeocoder *destinationPin = [[CLGeocoder alloc] init];
__block NSString *destinationPinName;

[destinationPin reverseGeocodeLocation:destination completionHandler:^(NSArray *placemarks, NSError *error) {
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
if(placemarks && placemarks.count > 0)
{
CLPlacemark *topResult = [placemarks objectAtIndex:0];

NSString *addressTxt = [NSString stringWithFormat:@"%@ %@,%@ %@",
[topResult subThoroughfare],[topResult thoroughfare],
[topResult locality], [topResult administrativeArea]];

destinationPinName = [[NSString alloc] initWithString:addressTxt];
}
}];

annotation = [[MQAnnotation alloc] initWithTitle:destinationPinName andCoordinate:touchMapCoordinate];

我在函数入口点、函数的两个 if block 内以及我分配注释的函数之后设置了断点。当我到达 reverseGeocodeLocation block 时,destinationPin 具有有效值,但我的程序一直直接跳转到函数调用后设置的断点。任何想法可能会发生什么??

最佳答案

reverseGeocodeLocation 的执行是异步完成的。当该后台任务完成时,将调用您的完成 block 。所以你看到的是正确的行为。对 reverseGeocodeLocation 的调用会立即返回,远早于它完成并且远早于您的完成处理程序被调用。您需要更新代码,以便在完成处理程序中创建注释。

关于iphone - 尝试调用 reverseGeocodeLocation,但程序一直跳过函数调用。有任何想法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13013076/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com