在我的地圖中有很多annotationView,每個annotationView都有自己的圖像, annotationView的數據取自數據庫中的不同表格。 當我選擇unannotationView我想顯示另一個viewController並做到這一點,我需要傳遞表名,這是一個字符串。我如何? 我試過,但我得到這個錯誤:將一個字符串傳遞給一個註解View
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 */
}
不再是同樣的錯誤,但選擇annotationView –
有一個時候,我不能把這個字符串看看Anna Karenina上面的答案。註釋的屬性應該在創建時設置。 – NikosM