我正在使用MapKit框架制作一个iOS应用程序。我已经得到的功能工作,但我现在有麻烦时,改变标注的图标。我可以改变annotation图标,但当我这样做时,annotation会失去它的标题和副标题值(点击时什么都不弹出)。我想也许这个问题是由于诸如第一次制作时不给注释标识符之类的东西,但我不确定…
如果有人能让我知道发生了什么,我将不胜感激!添加注释的代码是:
-(void)addAnnotationAtLattitude:(double)lattitude withLongitude:(double)longitude withTitle:(NSString *)title withSubtitle:(NSString *)subtitle{
//Handles the adding off the anotation
CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = lattitude;
annotationCoord.longitude = longitude;
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = title;
annotationPoint.subtitle = subtitle;
[self.MessageMap addAnnotation:annotationPoint];
}
和改变图标的代码(通过委托方法)是:
-(MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id
<MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationViewID];
}
annotationView.image = [UIImage imageNamed:@"CustomMapAnnotationIcon"];//mycustom image
annotationView.annotation = annotation;
return annotationView;
}
是否将annotationView.enabled
和annotationView.canShowCallout
设置为YES
?