My annotations doesn't show the Sub Title in the PIN

…衆ロ難τιáo~ 提交于 2019-12-11 07:14:26

问题


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

回答1:


The MKAnnotation protocol defines the subtitle property as:

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

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

Change the method declaration to:

-(NSString*)subtitle



回答2:


change subTitle to subtitle in method declaration and property declaration and it will work. :) happy coding,



来源:https://stackoverflow.com/questions/8743790/my-annotations-doesnt-show-the-sub-title-in-the-pin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!