2010-12-08 57 views
0

J'ai un code que je donne des coordonnées, titre, sous-titre, informations sur l'emplacement du fichier image. Cette information est utilisée pour générer l'annotation pour une broche ios mapkit. Le titre et le sous-titre sont automatiquement branchés et je peux saisir les autres informations (emplacement du fichier image) après que la broche soit sélectionnée. Je cherche à afficher une vignette de l'image dans l'annotation (pin popup) mais j'ai du mal à le définir comme une variable pour l'obtenir à partir de mes informations par opposition à coder dur. Ci-dessous le code que j'utilise pour générer ma carte/épingles.Obtenez variable et branchez-le dans 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

Veuillez vérifier la mise en forme. –

Répondre

0

De quoi dispose l'objet d'annotation? Avez-vous essayé ce qui suit?

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