给定自定义图标时,MKAnnotation会丢失标题和副标题

时间:2013-05-03 10:46:16

标签: objective-c xcode

好的,我正在使用MapKit框架制作iOS应用程序。我已经使用了这些功能,但是在更改注释图标时遇到了麻烦。我可以更改注释图标但是当我这样做时,注释会丢失它的标题和副标题值(点击时不会弹出任何内容)。我想也许问题可能是因为在首次制作时没有给注释标识符,但我不确定......

如果有人能告诉我发生了什么,我们将不胜感激!

添加注释的代码是:

-(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;

}

1 个答案:

答案 0 :(得分:0)

annotationView.enabledannotationView.canShowCallout是否设为YES