2013-05-03 28 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