を実装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