更新注释的副标题

时间:2013-05-09 08:40:50

标签: ios xcode annotations android-mapview

点击后,我正在努力在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中获取一些行...但是我不知道如何更新特定注释的副标题?

提前致谢! :)

1 个答案:

答案 0 :(得分:0)

    id<MKAnnotation> selectedAnn = view.annotation;
[mapview removeAnnotation:selectedAnn];

.. Add Annotation with new subtitle

[mapview addAnnotation:newselectedAnn];
[newselectedAnn setSelected:Yes animated:No];

希望这有帮助