用UIAlertViewStylePlainTextInput编辑注释文本

我可以将引脚标注放到具有泄露button的地图上。 当单击该button时,会popup一个alertView,在其中可以删除选定的注释。 我现在正在尝试使用UIAlertViewStylePlainTextInput编辑选定的注释字幕。 任何想法如何我可以做到这一点?

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { NSLog(@"Annotation button clicked"); UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Annotation" message:@"Edit Subtitle" delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Update Subtitle", @"Remove Pin",nil]; alert.alertViewStyle = UIAlertViewStylePlainTextInput; [alert show]; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == 0) { NSLog(@"Hide button clicked"); } if (buttonIndex == 1) { NSLog(@"Update button clicked"); //eg subtitle.text = [[alertView textFieldAtIndex:0] text]; } if (buttonIndex == 2) { NSLog(@"Remove button clicked"); [self.map removeAnnotations:self.map.selectedAnnotations]; } } 

就像删除注释时一样,您可以使用地图视图的selectedAnnotations属性访问选定的注释以更新其subtitle

以下示例假定您使用注释类MKPointAnnotation (具有可设置的subtitle属性)作为注释,但是您可以根据需要将其replace为您的类:

 NSLog(@"Update button clicked"); //eg subtitle.text = [[alertView textFieldAtIndex:0] text]; //Make sure there is a selected annotation... if (self.map.selectedAnnotations.count > 0) { //Since only one annotation can be selected at a time, //the selected annotation is the one at index 0... id<MKAnnotation> ann = [self.map.selectedAnnotations objectAtIndex:0]; //Make sure the selected annotation is one of our types... if ([ann isKindOfClass:[MKPointAnnotation class]]) { MKPointAnnotation *pa = (MKPointAnnotation *)ann; pa.subtitle = [[alertView textFieldAtIndex:0] text]; } }