MKAnnotationView does not appear on the map

I am trying to annotate my map with MKPointAnnotationfor example:

- (void)viewDidLoad
{
    NSLog(@"RootViewController viewDidLoad");

    [super viewDidLoad];

    CLLocationCoordinate2D coord = 
    CLLocationCoordinate2DMake(54.903683,23.895435);

    MKPointAnnotation *toyAnnotation = [[MKPointAnnotation alloc] init];

    toyAnnotation.coordinate = coord;
    toyAnnotation.title = @"Title";
    toyAnnotation.subtitle = @"Subtitle";

    [mapView addAnnotation:toyAnnotation];

    [toyAnnotation release];

}

- (MKAnnotationView *)mapView:(MKMapView *)m 
            viewForAnnotation:(id <MKAnnotation>)annotation
{
    NSLog(@"RootViewController mapView: viewForAnnotation:");
    NSLog(@"%@",annotation);

    MKAnnotationView *pin = [[MKAnnotationView alloc] 
                             initWithAnnotation:annotation 
                             reuseIdentifier:nil];

    pin.enabled = YES;
    pin.canShowCallout = YES;

    return [pin autorelease];
}

The contact does not appear on the map. RootViewControlleris the delegate for mapViewand thus the method mapView:viewForAnnotation:is called:

2011-11-24 15:04:03.808 App[2532:707] RootViewController mapView: viewForAnnotation:
2011-11-24 15:04:03.810 App[2532:707] <MKPointAnnotation: 0x1885c0>

What am I doing wrong and how to fix this problem?

+5
source share
1 answer

In viewForAnnotationcreate MKPinAnnotationViewinstead MKAnnotationView(for which you must install image).

Although to present annotations by default, you don’t need to implement the delegation method at all.

+18
source

All Articles