我的注释未显示PIN中的子标题

时间:2012-01-05 14:02:36

标签: ios mapkit mkannotation mkmapviewdelegate

在显示PINS的实施类中,我保留了两个变量(标题和子标题),在这个例子中,当我点击PIN时,只显示单词USA(标题)。 / p>

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

2 个答案:

答案 0 :(得分:7)

MKAnnotation协议将subtitle属性定义为:

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

注意subtitle全部为小写但您的班级有subTitle(大写T),地图视图不会调用。

将方法声明更改为:

-(NSString*)subtitle

答案 1 :(得分:1)

在方法声明和属性声明中将subTitle更改为subtitle,它将起作用。 :)快乐的编码,