Add Disclosure Button to MKPointAnnotation
ios
Solution
declare your class to be a `MKMapViewDelegate`. Then, add
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"String"];
if(!annotationView) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"String"];
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
return annotationView;
}
Then you add:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// Go to edit view
ViewController *detailViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
... ViewController can be anything you defined (I use nib-files...)
Problem
To create a map annotation in a storyboard iOS project, I used: ``` CLLocationCoordinate2D annotationCoord3; annotationCoord3.latitude = 34.233129; annotationCoord3.longitude = -118.998644; MKPointAnnotation *annotationPoint3 = [[MKPointAnnotation alloc] init]; annotationPoint3.coordinate = annotationCoord3; annotationPoint3.title = @"Another Spot"; annotationPoint3.subtitle = @"More than a Fluke"; [_mapView addAnnotation:annotationPoint3]; ``` It works great but I'd like to add a disclosure button so I can push seque to a new view controller and display image. Is this possible? Thx in advance, --bd--