我的注释未在PIN中显示副标题 [英] My annotations doesn't show the Sub Title in the PIN

查看:119
本文介绍了我的注释未在PIN中显示副标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在负责显示PINS的实现类中,我保留了两个变量(标题和副标题),在此示例中,当我单击PIN时仅显示单词USA(标题).

in the implementations class charged of displaying PINS, i have reserved two variables (title and sub title), in this example, only the word USA (the title) is displayed when i click on the 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类中,我为标题和副标题保留了两个变量.

Although, in ManageAnnotations class, i have reserved two variables for the title and the subtitle.

@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

推荐答案

MKAnnotation协议将subtitle属性定义为:

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

注意subtitle都是小写,但是您的班级有subTitle(大写T),地图视图不会调用.

Note subtitle is all lowercase but your class has subTitle (uppercase T) which the map view will not call.

将方法声明更改为:

-(NSString*)subtitle

这篇关于我的注释未在PIN中显示副标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆