将定制属性添加到MKAnnotation
我正在尝试添加一个自定义值到我的MKAnnotation。 我想要它存储的位置的唯一ID。 我用代码来设置标题和副标题的注释是这样的:
location.latitude = [dictionary[@"placeLatitude"] doubleValue]; location.longitude = [dictionary[@"placeLongitude"] doubleValue]; newAnnotation = [[MapViewAnnotation alloc] initWithTitle:dictionary[@"placeName"] andCoordinate:location]; newAnnotation.subtitle = dictionary[@"placeCity"];
我将如何添加自定义属性,例如“placeId”? 这是我有:
newAnnotation.placeId=dictionary[@"placeId"];
任何帮助将是伟大的。 谢谢!
如果MapViewAnnotation是MKAnnotation / MKAnnotationView的子类,那么简单地为它创build属性,合成和使用。 如果不是,则通过MKAnnotationView创build类别。
以下是创build类别类的步骤。
- 右键单击项目并select“新build文件”
- Cacoa Touch> Objective-C类别>下一步
- 在Category_on_class上inputcategory:category_name&Category
- 在.h文件中只需创buildplaceId的属性
- 在.m中使用@dynamic进行合成
- 将.h文件导入到您的文件中。
那么你可以在该类的“classObject”对象上有“classObject.placeId”属性。
做Bhargavi说的,但是去做MapViewAnnotation.m和MapViewAnnotation.h