I wrote this code to create a custom annotation image
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *google = @"googlePin";
if ([annotation isKindOfClass:[myClass class]])
{
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:google];
if (!annotationView)
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:google];
annotationView.image = [UIImage imageNamed:@"pin.png"];
}
return annotationView;
}
return nil;
}
The image is appearing on the map; however when I click on it nothing happen, no title nor subtitle.
Do you guys have any idea?
When you override
viewForAnnotation, you have to setcanShowCallouttoYES(the default on a new view you alloc/init isNO).If you don’t override that delegate method, the map view creates a default red pin with
canShowCalloutalready set toYES.However, even with
canShowCalloutset toYES, the callout will still not appear if the annotation’stitleisnilor blank (empty string).(But again, if the
titleis notniland not blank, the callout won’t show unlesscanShowCalloutisYES.)