1

PINS の表示を担当する実装クラスでは、2 つの変数 (タイトルとサブタイトル) を予約しました。この例ではUSA、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
4

2 に答える 2

7

MKAnnotationプロトコルは、subtitleプロパティを次のように定義します。

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

subtitleはすべて小文字ですが、クラスにはマップビューが呼び出さないsubTitle(大文字) があります。T

メソッド宣言を次のように変更します。

-(NSString*)subtitle
于 2012-01-05T14:14:12.087 に答える