2010-12-08 76 views
0

我有代碼,我給出的座標,標題,字幕,圖像文件的位置信息。該信息用於生成ios mapkit引腳的註釋。標題和副標題會自動插入,我可以在選中引腳後抓取其他信息(圖像文件位置)。我正在尋找在註釋(pin彈出)中顯示圖像的縮略圖,但是我無法將其設置爲一個變量,以從我的信息中獲取它,而不是對它進行硬編碼。以下是我用來生成地圖/別針的代碼。獲取變量,並將它插入MKAnnotationView

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 
    // Boilerplate pin annotation code 
UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

NSString *imageLoc; 

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.map dequeueReusableAnnotationViewWithIdentifier: @"restMap"]; 
    if (pin == nil) { 
     pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"restMap"] autorelease]; 

    } else { 
     pin.annotation = annotation; 
} 

    pin.pinColor = MKPinAnnotationColorRed; 
    pin.canShowCallout = YES; 
    pin.animatesDrop = YES; 

NSString *imageLoc= ???????????? 

UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageLoc]]; 
    pin.leftCalloutAccessoryView = leftIconView; 

    [detailButton addTarget:self action:@selector(showDetailView:) forControlEvents:UIControlEventTouchUpInside]; 
    pin.rightCalloutAccessoryView = detailButton; 
    return pin; 
} 

@interface MapPin : NSObject <MKAnnotation> { 

    CLLocationCoordinate2D coordinate; 
    NSString *subtitle; 
    NSString *title; 
NSString *indexnumber; 
NSString *imageFile; 
} 

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; 
@property (nonatomic, readonly) NSString *title; 
@property (nonatomic, readonly) NSString *subtitle; 
@property (nonatomic, readonly) NSString *indexnumber; 
@property (nonatomic, readonly) NSString *imageFile; 

-(id)initWithCoordinates:(CLLocationCoordinate2D)location 
       placeName: placeName 
      description:description 
    indexnum:indexnum 
    imageFileLoc:imageFileLoc; 

@end 


#import "MapPin.h" 

@implementation MapPin 

@synthesize coordinate; 
@synthesize title; 
@synthesize subtitle; 
@synthesize indexnumber; 
@synthesize imageFile; 

-(id)initWithCoordinates:(CLLocationCoordinate2D)location 
       placeName: placeName 
      description:description 
    indexnum:indexnum 
    imageFileLoc:imageFileLoc{ 

    self = [super init]; 
    if (self != nil) { 
    imageFile=imageFileLoc; 
    [imageFile retain]; 
    indexnumber=indexnum; 
    [indexnumber retain]; 
     coordinate = location; 
     title = placeName; 
     [title retain]; 
     subtitle = description; 
     [subtitle retain]; 
    } 
    return self;  
} 
+0

請檢查您的格式。 – 2010-12-08 23:03:15

回答

0

註解對象有什麼可用的?你嘗試過以下嗎?

NSString *imageLoc = [annotation respondsToSelector:@selector(imageFile)] ? [annotation imageFile] : @"some_default_value"; 
相關問題