2012-08-23 55 views
2

我設置標題兩個MKAnnotationViewMKAnnotationView不顯示標題

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: 
(id <MKAnnotation>)annotation 
{ 

if(([annotation isKindOfClass:[Test_flag class]])) 
{ 

    MKAnnotationView *pinView = nil; 

    if(annotation != mapView.userLocation) 
    { 
     static NSString *defaultPinID = @"PinId1"; 
     pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
     if (pinView == nil) pinView = [[[MKAnnotationView alloc] 
              initWithAnnotation:annotation reuseIdentifier:@"pin1"] autorelease]; 
     pinView.canShowCallout = YES; 
     pinView.animatesDrop = YES; 
     [pinView setImage:[UIImage imageNamed:@"flg.png"]]; 
     [pinView setSelected:YES animated:YES]; 

    } 
    else 
    { 
     [mapView.userLocation setTitle:@"I am here"]; 
    } 
    return pinView; 
} 
else if(([annotation isKindOfClass:[Distance1 class]])) 
{ 
    MKAnnotationView *pinView = nil; 

    if(annotation != mapView.userLocation) 
    { 
     static NSString *defaultPinID = @"PinId4"; 
     pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
     if (pinView == nil) pinView = [[[MKAnnotationView alloc] 
              initWithAnnotation:annotation reuseIdentifier:@"pin4"] autorelease]; 

     pinView.canShowCallout = YES; 
     [pinView setImage:[UIImage imageNamed:@"Circle_Grey.png"]]; 
     [pinView setSelected:YES animated:YES]; 

    } 
    else 
    { 
     [mapView.userLocation setTitle:@"I am here"]; 
    } 
    return pinView; 
} 

當我觸摸地圖,無論是MKAnnotationView被指出,但他們不顯示標題。是什麼原因?請幫我找。

+0

按照SO回答http://stackoverflow.com/questions/5589181/displaying-pin-with-title-annotation-once-map-loads – Deepesh

回答

0

你錯過了寫title方法Test_flag類。

+0

我已經添加了NSString *標題和@屬性,@綜合也在Test_flag類 – Madhumitha

+0

當您向地圖添加註釋時,請將該值設置爲標題。現在硬編碼返回溫度值來檢查。 – Apurv

+0

,我也喜歡test_flag.title = @「距離」; test_flag.subtitle = @「0.0」; – Madhumitha