How to get the title and subtitle for a pin when we are implementing the MKAnnotation?

天涯浪子 提交于 2019-12-11 16:28:02

问题


I have implemented the MKAnnotation as below. I will put a lot of pins and the information for each of those pins are stored in an array. Each member of this array is an object whose properties will give the values for the title and subtitle of the pin. Each object corresponds to a pin. But how can I display these values for the pin when I click a pin??

@interface UserAnnotation : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;

NSString *title;
NSString *subtitle;
NSString *city;
NSString *province;
}

@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;
@property (nonatomic, retain) NSString *city;
@property (nonatomic, retain) NSString *province;

-(id)initWithCoordinate:(CLLocationCoordinate2D)c;

And .m is

@implementation UserAnnotation

@synthesize coordinate, title, subtitle, city, province;

- (NSString *)title
{
 return title;
}

- (NSString *)subtitle
{
 return subtitle;
}

- (NSString *)city
{
 return city;
}

- (NSString *)province
{
 return province;
}

-(id)initWithCoordinate:(CLLocationCoordinate2D)c
{
coordinate=c;
NSLog(@"%f,%f",c.latitude,c.longitude);
return self;
}


@end

回答1:


Ony two lines were added and all were done.

annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);


来源:https://stackoverflow.com/questions/3054374/how-to-get-the-title-and-subtitle-for-a-pin-when-we-are-implementing-the-mkannot

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