2011-11-24 45 views
5

Tôi cố gắng để chú thích bản đồ của tôi với MKPointAnnotation, như thế này:MKAnnotationView không hiển thị trên bản đồ

- (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 không xuất hiện trên bản đồ. RootViewController là một đại biểu cho mapView và do đó mapView:viewForAnnotation: phương pháp được gọi là:

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> 

Tôi đang làm gì sai và làm thế nào để khắc phục vấn đề này?

Trả lời

18

Trong viewForAnnotation, tạo MKPinAnnotationView thay vì MKAnnotationView (bạn phải đặt image).

Mặc dù cho chế độ xem chú thích mã pin mặc định, bạn không cần triển khai phương thức ủy nhiệm.

Các vấn đề liên quan