0

を実装MKMapViewDelegateしましたが、何らかの理由でviewForAnnotationメソッドが呼び出されません。

MapView上にアノテーションが表示されていることを確認できます。

メソッドに を追加しましたNSLog()が、ログ ステートメントが出力されません。

他のメソッドのステートメントが出力されるMKMapViewDelegateため、私のクラスは間違いなくそうです。NSLog()MKMapViewDelegate

私も設置self.mapView.delegate = selfしていますviewDidLoad

@interface MapViewController () <MKMapViewDelegate>
    @property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end

@implementation MapViewController

    @synthesize mapView = _mapView;
    @synthesize annotations = _annotations;


    -(void)setMapView:(MKMapView *)mapView
    {
        _mapView = mapView;
        [self updateMapView];
    }

    -(void)setAnnotations:(NSArray *)annotations
    {
        _annotations = annotations;
         [self updateMapView];
    }


    -(MKAnnotationView *)mapView:(MKMapView *)mapView
               viewForAnnotation:(id<MKAnnotation>)annotation
    {
     // For some reason this method is never called!!!!!!
     NSLog(@"This logging statement is never printed");

   }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.mapView.delegate = self;
    }

    - (void)updateMapView
    {
        if (self.mapView.annotations) [self.mapView removeAnnotations:self.mapView.annotations];
        if (self.annotations) [self.mapView addAnnotations:self.annotations];
    }

@end
4

2 に答える 2

0

考えられる説明は、注釈がないことです。

にアノテーションを実際に追加しているコードを確認してくださいmapView

于 2013-01-27T18:26:22.103 に答える