I have an UIViewController
class to manage an MKMapView
defined like this:
@interface MapViewController : UIViewController <MKMapViewDelegate>
Within the implementation of this view controller, I have:
- (void)loadView
{
MKMapView *mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
mapView.delegate = self;
self.view = mapView;
}
- (void)centerMapInLoc:(CLLocation *)loc
{
CustomAnnotation *annotation = [[CustomAnnotation alloc] initWithCoordinates:loc.coordinate title:@"My position" subTitle:nil];
[(MKMapView *)self.view addAnnotation:annotation];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *v = nil;
// Custom logic
v.annotation = annotation;
return v;
}
Being centerMapInLoc:
a public method I call from another view controller. The annotation is created within such method, but viewForAnnotation:
delegate method is not called when the annotation is added. I don't understand why, since the delegate is set in loadView
method.
Thanks in advance