2011-11-24 14 views
5

Estoy tratando de anotar mi mapa con MKPointAnnotation, así:no MKAnnotationView a aparecer en el mapa

- (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]; 
} 

Pin no aparece en el mapa. RootViewController es un delegado para mapView y por lo tanto mapView:viewForAnnotation: método se llama:

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> 

¿Qué estoy haciendo mal y cómo solucionar este problema?

Respuesta

18

En viewForAnnotation, cree MKPinAnnotationView en lugar de MKAnnotationView (para lo cual debe configurar el image).

Aunque para una vista de anotación de pin predeterminada, no es necesario implementar el método de delegado en absoluto.

Cuestiones relacionadas