在我的地图中有很多 annotationView,每个都有自己的图像,annotationView 的数据取自数据库中的不同表。当我选择 un'annotationView 时,我想显示另一个 viewController,为此我需要传递表名,它是一个字符串。我如何能?我试过了,但我得到了这个错误:
No know instance method for selector 'setNameTable:'
这是 MapViewController.m 中的代码
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id
<MKAnnotation>)annotation
{
//....
if ([annotation isKindOfClass:[AnnotationCustom class]]){
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView *annotationView = (MKPinAnnotationView*) [mapView
dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier];
if ([self.name isEqualToString:@"MyTable"]){
if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){
annotationView.image = [UIImage imageNamed:@"iphone_myTable.png"];
[annotationView.annotation setNameTable:[NSString
stringWithFormat:self.name]]; //the error is here
//nameTable is a property of AnnotationCustom class
}else{
annotationView.image = [UIImage imageNamed:@"ipad_myTable.png"];
[annotationView.annotation setNameTable:[NSString
stringWithFormat:self.name]];//the error is here
//nameTable is a property of AnnotationCustom class
}
//.......
}
在委托方法中,我必须传递字符串
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control{
AnnotationCustom *customAnnotation = (AnnotationCustom *)view.annotation;
[customAnnotation setNameTable:[NSString stringWithFormat:@"%@",self.name]];
NSLog(@"The name table is %@",customAnnotation.nameTable);
/*the name is wrong, the string self.name is relative to last table open and not the
table selected */
}