我的注释未在 PIN 中显示子标题
在负责显示PINS的实现类中,我保留了两个变量(标题和副标题),在本例中,当我单击PIN时,仅显示单词USA
(标题)。
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
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];
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MKAnnotation
协议将subtitle
属性定义为:注意
subtitle
全部小写,但您的类有subTitle
(大写 < code>T) 地图视图不会调用它。将方法声明更改为:
The
MKAnnotation
protocol defines thesubtitle
property as:Note
subtitle
is all lowercase but your class hassubTitle
(uppercaseT
) which the map view will not call.Change the method declaration to:
将方法声明和属性声明中的 subTitle 更改为副标题即可。
:) 快乐编码,
change subTitle to subtitle in method declaration and property declaration and it will work.
:) happy coding,