2012-01-05 58 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

變化副標題副標題在方法聲明及財產申報,它會工作。 :)快樂編碼,