我已经实现了我的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