2013-05-03 98 views
0

好吧,我正在使用MapKit框架制作iOS应用程序。我已经可以使用这些功能,但现在在更改注释图标时遇到了麻烦。我可以更改注释图标,但是当我这样做时注释会丢失标题和字幕值(点击时不会弹出)。我认为也许这个问题是由于类似的东西没有给第一次做标识符时,但我不知道...当给出自定义图标时,MKAnnotation会丢失标题和副标题

如果任何人都可以让我知道最新情况将不胜感激!

添加注释的代码是:

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

}

回答

0

annotationView.enabledannotationView.canShowCallout设置为YES

+0

你是对的。我以为我已经尝试过,但显然不是!非常感谢。 – CreativeAbyss 2013-05-03 11:02:25