Ios 自定义注释don'的属性;在委托方法中不可见
我有许多自定义注释,我给了它们属性(NameTable和ID)。我在创建之前设置了这个属性,但是委托方法中的这些属性不再可见。我有多个与从数据库中获取的表元素关联的注释。如何使它们在委托方法中可见Ios 自定义注释don'的属性;在委托方法中不可见,ios,nsstring,mkmapview,mkannotationview,mkpinannotationview,Ios,Nsstring,Mkmapview,Mkannotationview,Mkpinannotationview,我有许多自定义注释,我给了它们属性(NameTable和ID)。我在创建之前设置了这个属性,但是委托方法中的这些属性不再可见。我有多个与从数据库中获取的表元素关联的注释。如何使它们在委托方法中可见 - (void)viewDidLoad { //...... for(int i=0; i<6; i++){ //loop for create multiple annotations AnnotationCustom *annotationIcone =[[An
- (void)viewDidLoad
{
//......
for(int i=0; i<6; i++){ //loop for create multiple annotations
AnnotationCustom *annotationIcone =[[AnnotationCustom alloc]initWithCoordinates:coord
title:self.myTable.title subTitle:self.myTable.address];
annotationIcone.nameTable = [NSString stringWithFormat:@"%@", self.myTableName];
annotationIcone.ID = i+1;
[self.mapView addAnnotation: annotationIcone;
//.....
}
在viewForAnnotation中,您需要告诉编译器注释实际上是一个AnnotationCustom对象 因此,您首先需要执行以下操作:
AnnotationCustom *annotationCustom = (AnnotationCustom *)annotation;
然后尝试访问nameTable属性
在didSelectAnnotationView方法中,如果要获取所选注释的nameTable值,则需要执行以下操作:
AnnotationCustom *annotationCustomSelected = (AnnotationCustom *)view.annotation;
NSLog(@"table name of annotation selected: %@", annotationCustomSelected.nameTable);
非常简单,但非常感谢!
AnnotationCustom *annotationCustom = (AnnotationCustom *)annotation;
AnnotationCustom *annotationCustomSelected = (AnnotationCustom *)view.annotation;
NSLog(@"table name of annotation selected: %@", annotationCustomSelected.nameTable);