我有许多自定义注释,我向其提供了属性(NameTable 和 ID)。我在 AddAnnotation 创建的那一刻之前设置了这个属性,但是这些属性在委托方法中不再可见。我有多个注释与从数据库中获取的表元素相关联。如何使它们在委托方法中可见?
- (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;
//.....
}
但是在委托方法中:
(MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id
<MKAnnotation>)annotation
{
NSLog(@"The name of table is:@"%@", annotation.nameTable);
//property 'nameTable' not found on object of type '_strong id <MKAnnotation>
NSLog (@The name of table is:@%@", annotation.ID);
//property 'ID' not found on object of type '_strong id <MKAnnotation>
//......
}
在另一种方法中:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
NSLog(@"The name of table is %@", self.myTableName);
// here I get the name of last table open and not the name of table selected
}