0
我一直在設置MapView中的註釋的副標題,只要點擊它,我們就掙扎着。更新註釋的副標題
.M:
MKCoordinateRegion England = { {0.0, 0.0} , {0.0, 0.0} };
England.center.latitude = 51.50063;
England.center.longitude = -0.124629;
England.span.longitudeDelta = 100.0f;
England.span.latitudeDelta = 100.0f;
[mapView setRegion:England animated:YES];
Annotation *ann1 = [[Annotation alloc] init];
ann1.title = @"England";
ann1.subtitle = @"subtitle";
ann1.coordinate = England.center;
[mapView addAnnotation:ann1];
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation: (id<MKAnnotation>)annotation {
MKPinAnnotationView *MyPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"]; MyPin.pinColor = MKPinAnnotationColorPurple;
UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[advertButton addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
MyPin.rightCalloutAccessoryView = advertButton;
MyPin.draggable = NO;
MyPin.highlighted = YES;
MyPin.animatesDrop = TRUE;
MyPin.canShowCallout = YES;
return MyPin;
}
- (void)mapView:(MKMapView *)mapView1 didSelectAnnotationView:(MKAnnotationView *)view
{
id<MKAnnotation> selectedAnn = [mapView.selectedAnnotations objectAtIndex:0];
country_title = selectedAnn.title;
selectedAnn.subtitle = @"NEW SUBTITLE";
}
如何設置字幕一旦註釋已經被點擊?我不想這樣做,因爲我點擊時從mysql獲取了一些行..但我不知道如何更新特定註釋的副標題?
在此先感謝! :)
嗨Mohith!感謝您的快速回復。不幸的是,我很困惑該放哪一行?我已經在我的didSelectAnnotationView:id selectedAnn = [mapView.selectedAnnotations objectAtIndex:0]; ...我很新的這個:( –
2013-05-09 09:06:17
用我的代碼段替換整個內容 – Mohith 2013-05-09 09:07:20
我試過你的片段,但它只能讓我把一個新的註釋放在一個特定的地方,如果它不是我單擊的註釋,那麼該怎麼辦?你不能只設置一個NSString屬性,然後說:id selectedAnn = view.annotation;country_title = selectedAnn.title ; if([country_title isEqualToString:@「USA」]){ subtitle_USA = @「NEW SUBTITLE」; } –
2013-05-11 07:05:04