2012-01-05 13 views
1

実装クラスでPINSを表示していますが、私は2つの変数(タイトルとサブタイトル)を予約しています。この例では、単語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クラスでは、タイトルとサブタイトルの2つの変数を予約していますが、

@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プロパティを定義します:注subtitleはすべて小文字ですが、あなたのクラスは、マップビューを呼び出しませんsubTitle(大文字T)が

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

変更メソッド宣言に:

-(NSString*)subtitle 
+0

百万点:) – Malloc

1

変更サブタイトルは、メソッドの宣言とプロパティの宣言を字幕にすると、それは動作します。 :)ハッピーコーディング、

関連する問題