I created an object that receives a coordinate and suppose to return a placemark after reverse geocoding it. Problem is that this method is a-synchronic, so I need a way to return the placemark once it was found. In my view controller I call this:
[getzip reverseGeocodeCurrentLocation:coordinate];
where getzip is an instance of an object that implements this (which is still empty in my case….):
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
Now, once I get into reverseGeocoder:didFindPlacemark, how can I return the placemark back to the viewcontroller?
I tried to do the same thing as I saw in some examples being done with LocationManager, where a locationUpdate method is being called from locationManager:didUpdateToLocation:fromLocation, and implementing the locationUpdate in the viewcontroller, but it did not work. In other words, I did that:
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
[self.delegate setPlacemark:placemark];
}
and implemented setPlacemark in the viewcontroller, but it doesnt get to setPlacemark from some reason (BTW, the placemark is correct once I call setPlacemark:placemark within reverseGeocoder).
Thanks!
As per your comments,
self.delegateisnilwhen[self.delegate setPlacemark:placemark];inreverseGeocoder:didFindPlacemark:is executed. Therefore, nothing happens.You must set the
delegateproperty to your view controller beforereverseGeocoder:didFindPlacemark:gets called. If the variablegetzipin your view controller is an instance of the class that implementsreverseGeocoder:didFindPlacemark:(GetZipCode?), you would do this in your view controller:As I said in my comment, by making your view controller conform to the
GetZipcodeDelegateprotocol means your view controller can be the delegate because it responds to the messages that the object that is delegating will potentially send to its delegate. It does not mean that it is the delegate.