0

In my application I am using mapkit. All the time I have more than one annoatations on the map. In the callout i have placed the detailDisclosureButton. On the click of this button I want to load new viewController. How to do this?

Thanks in advance.

3 Answers 3

2

In - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )annotation delegate add a disclosure button as -

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;

and in its action method -

-(IBAction) infoButtonPressed:(id) sender
{
    DetailViewController *dvc = [[DetailViewController alloc] init];
    [self.navigationController pushViewController:dvc animated:YES];
}
2
  • It works. In the selector ":" is not there. it should be only (infoButtonPressed).
    – Harsh
    Jul 25, 2011 at 5:53
  • it depends on you whether you need sender instance or not.
    – saadnib
    Jul 25, 2011 at 6:21
1
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation
{

    //Some code here
    pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    return pinView;
}

And make use of the following delegate method to get the button action

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// code to show details view
}
0

I would check here: Modal View Controller Reference to see how to move from one view to another. When the detailDisclosureButton is pressed, set up the viewController you want to move to, and use the methods described in the link. Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.