次のコードは、「注釈が選択されていません」というメッセージを返します。CalloutAccessoriesデリゲートは、選択された注釈を特定するのに役立ちます。私のコードは以下の通りです。何か案は)?前もって感謝します
「RemoveViewController.m」
- (IBAction)removePin:(id)sender {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[appDelegate viewController] removeAnno];
[self.navigationController popViewControllerAnimated:YES];
}
「ViewController.m」
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
if ([(UIButton*)control buttonType] == UIButtonTypeDetailDisclosure){
// Do your thing when the detailDisclosureButton is touched
RemoveViewController *settingAnnotation = [[RemoveViewController alloc]initWithNibName:@"RemoveViewController" bundle:nil];
Annotation *annotation1;
annotation1 = view.annotation;
settingAnnotation.title = annotation1.title;
settingAnnotation.subtitle = annotation1.subtitle;
[self.navigationController pushViewController:settingAnnotation animated:YES];
}
}
- (void)removeAnno{
[mapView removeAnnotations: mapView.selectedAnnotations];
if (mapView.selectedAnnotations.count == 0)
{
NSLog(@"no annotation selected");
}
else
{
id<MKAnnotation> ann = [mapView.selectedAnnotations objectAtIndex:0];
CLLocationCoordinate2D coord = ann.coordinate;
NSLog(@"lat = %f, lon = %f", coord.latitude, coord.longitude);
}
}