【发布时间】:2013-01-27 18:05:22
【问题描述】:
我已经实现了我的MKMapViewDelegate,但由于某种原因,我的viewForAnnotation 方法从未被调用过。
我可以确认 MapView 上显示了注释。
我在我的方法中添加了一个NSLog(),并且从未打印过日志记录语句。
我知道我的类肯定是MKMapViewDelegate,因为其他MKMapViewDelegate 方法中的NSLog() 语句被打印出来了。
我也在viewDidLoad中设置self.mapView.delegate = self
@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
【问题讨论】:
-
你在.h文件中添加函数了吗?
-
你能用
updateMapView方法的实现来修正你的问题吗?您能否确认已将注释正确添加到地图视图中? -
我已经添加了 updateMapView 方法。我可以确认注释确实已经出现在屏幕上。
标签: ios mkmapview mkmapviewdelegate