在实现MKAnnotation时,如何获取图钉的标题和副标题? [英] How to get the title and subtitle for a pin when we are implementing the MKAnnotation?

查看:99
本文介绍了在实现MKAnnotation时,如何获取图钉的标题和副标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了如下的MKAnnotation.我将放置很多引脚,每个引脚的信息都存储在一个数组中.该数组的每个成员都是一个对象,其属性将提供该引脚的标题和副标题的值.每个对象都对应一个图钉.但是当我单击图钉时如何显示这些值?

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;

.m是

@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

推荐答案

仅添加了两行,并且都已完成.

Ony two lines were added and all were done.

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

这篇关于在实现MKAnnotation时,如何获取图钉的标题和副标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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