I want to add a button to the annotation view and assign an action to it. I’ve kind of figure it out only my code has a small issue.
// so when I touch the pin , and the annotation view is displayed , I create a button and add it to the view
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
// when the button is pressed , go to another view
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"calloutAccessoryControlTapped");
ArticleViewController *det = [[ArticleViewController alloc]init];
det.leTitle = view.annotation.title;
det.link = @"http://en.wikipedia.org/wiki/San_Francisco";
[self.navigationController pushViewController:det animated:YES];
}
Now , the problem is that the first time I touch the annotation and the button is created ,
the
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
function doesn’t work . Only after I deselect the annotation and touch it again it works properly . Could you help me impove my code ? Thanks.
Found it !
I just had to add the button in a function that is called before the one I put it first in .