我认为你的做法是错误的,没有理由阻止,你要做的是让该方法返回 void,并在处理地理编码的类中,定义一个协议,该协议有一个方法说 -( void)didReceivePlacemark:(id)placemark,placemark可以是nil也可以是某个placemark,在geocoder返回时调用。您还为您的类创建了一个委托属性,因此任何人都可以订阅协议...然后在调用类中订阅协议并实现该方法...这里有更多关于协议的信息
希望对您有所帮助这是一个示例:因此,执行地理编码的类的接口看起来像这样
@protocol GeocoderControllerDelegate
-(void)didFindGeoTag:(id)sender; // this is the call back method
@end
@interface GeocoderController : NSObject {
id delegate;
}
@property(assign) id <GeocoderControllerDelegate> delegate;
然后在实现中你会看到这样的东西
- (void) getAddress:(CLLocationCoordinate2D) coordinate
{
[self startGeocoder:coordinate];
}
- (void)reverseGeocoder:(MKReverseGeocoder*)geocoder didFindPlacemark:(MKPlaseMark*)plasemark
{
[delegate didFindGeoTag:plasemark];
}
- (void)reverseGeocoder:(MKReverseGeocoder*)geocoder didFailWithError:(NSError*)error
{
[delegate didFindGeoTag:nil]
}
在调用类中,您只需设置 GeocoderClass 的委托属性,并实现协议,实现可能看起来像
-(void)findMethod
{
GeocoderController *c=...
[c setDelegate:self];
[c findAddress];
//at this point u stop doing anything and just wait for the call back to occur
//this is much preferable than blocking
}
-(void)didFindGeoTag:(id)sender
{
if(sender)
{
//do something with placemark
}
else
{
//geocoding failed
}
}