2012-01-05 60 views
1

中显示PIN标题,我已经预留了两个变量(标题和子标题),在本例中只显示USA(标题)字样当我点击PIN时。我的注释并没有在PIN

CLLocationCoordinate2D location2D = (CLLocationCoordinate2D){ .latitude = latitudeOfUserLocation, .longitude = longitudeOfUserLocation }; 
    ManageAnnotations *annotation=[[ManageAnnotations alloc]initWithTitle:@"USA" adresseDuTheme:@"Colorado" coordinate:location2D];//only USA is displayed 
    annotation.pinColor = MKPinAnnotationColorRed; //or red or whatever 
    [self->mapView addAnnotation:annotation]; 
    MKCoordinateSpan span={.latitudeDelta=1,.longitudeDelta=0.5}; 
    MKCoordinateRegion region={location2D,span}; 
    [mapView setRegion:region]; 

尽管在ManageAnnotations类中,我已经为标题和副标题保留了两个变量。

@interface ManageAnnotations : NSObject<MKAnnotation>{ 

    NSString *_libelle; 
    NSString *_adresse; 
    CLLocationCoordinate2D _coordinate; 

} 
// 
@property(nonatomic,assign)MKPinAnnotationColor pinColor; 
@property(copy)NSString *libelle; 
@property(copy)NSString *adresse; 
@property(nonatomic,readonly)CLLocationCoordinate2D coordinate; 

-(id)initWithTitle:(NSString*)libelle adresseDuTheme:(NSString*)adresse coordinate:(CLLocationCoordinate2D)coordinate; 
@end 


#import "ManageAnnotations.h" 

@implementation ManageAnnotations 

@synthesize pinColor; 
@synthesize libelle=_libelle; 
@synthesize adresse=_adresse; 
@synthesize coordinate=_coordinate; 
-(id)initWithTitle:(NSString*)libelle adresseDuTheme:(NSString*)adresse coordinate:(CLLocationCoordinate2D)coordinate{ 

    if((self=[super init])){ 
     _libelle=[libelle copy]; 
     _adresse=[adresse copy]; 
     _coordinate=coordinate; 

    } 
    return self; 

} 
-(NSString*)title{ 

    return _libelle; 
} 
-(NSString*)subTitle{ 
    return _adresse; 


} 


@end 

回答

7

MKAnnotation协议定义了subtitle属性为:

@property (nonatomic, readonly, copy) NSString *subtitle 

subtitle是全部小写,但你的类有subTitle(大写T)的地图视图不会叫。

变化的方法声明:

-(NSString*)subtitle 
+0

百万比:) – Malloc 2012-01-05 14:19:44

1

变化副标题副标题在方法声明及财产申报,它会工作。 :)快乐编码,