2012-06-12 32 views
0

我上課定義註解銷

@interface MyLocation : NSObject <MKAnnotation> 

@property (copy) NSString *name; 
@property (copy) NSString *address; 
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; 
@property (nonatomic, strong) UIImage *banner; 
@property (nonatomic, strong) NSString *descr; 

當我在地圖上添加位置我想,方法- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation顯示標題....我怎樣才能做到這一點?

- (MKAnnotationView*) mapView: 
(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
    { 
    static NSString *identifier = @"MyLocation"; 
    if ([annotation isKindOfClass:[MyLocation class]]) { 
     MKPinAnnotationView *annotationView = (MKPinAnnotationView*) 
     [mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 

     if (annotationView == nil) { 
      annotationView = [[MKPinAnnotationView alloc] 
    initWithAnnotation:annotation reuseIdentifier:identifier]; 
         } else { 
          annotationView.annotation = annotation; 
           } 
       annotationView.enabled = YES; 
       annotationView.canShowCallout = YES; 
       annotationView.image = [UIImage imageNamed:@"Image2.jpg"]; 

       return annotationView; 
     } 
     return nil; 
    } 

此方法更改所有註釋引腳,但我需要每個註釋的不同圖像。 感謝您的幫助!

回答

0

您必須使用MKAnnotationView作爲自定義引腳,因爲MKPinAnnotationView總是顯示「默認」引腳。

0

自定義類MKAnnotationView,和U可以改變 看到從蘋果示例代碼中的引腳:map callouts

+0

注意,[鏈路僅答案](http://meta.stackoverflow.com/tags/link-only -answers/info),所以SO答案應該是搜索解決方案的終點(而另一個引用的中途停留時間往往會隨着時間的推移而變得過時)。請考慮在此添加獨立的摘要,並將鏈接保留爲參考。 – kleopatra