- (NSString *) geocodeAddressFromCoordinate:(CLLocationCoordinate2D)coordinate
{
CLLocation *location = [[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
__block NSMutableString * address = [NSMutableString string];
geocoder = [[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
{
if (error) {
NSLog(@"%@", [error localizedDescription]);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No results were found" message:@"Try another search" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
alert.show;
return;
}
if ([placemarks count]>0)
{
NSLog([placemarks description]);
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(placemark.locality);
//This line makes an error
[address initWithString:placemark.locality];**
}
}];
return address;
}
了以下运行时错误:没有匹配的页头:错误当一个块分配的NSString变量
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* initialization method -initWithCharactersNoCopy:length:freeWhenDone: cannot be sent to an abstract object of class __NSCFString: Create a concrete instance!'
它停止崩溃,但地址为零:( – Shmidt
我发现块完成后功能,这就是为什么NSString是空的。你可以请任何建议吗? – Shmidt