Search code examples
iphonesdkmapkitstoryboardcallouts

Mapcall out in IOS5 with storyboard


I am working on an iphone app in IOS5 that user storyboards. I have created a storyboard that uses mapkit with annotation callouts. I was able to wire up push segues for buttons and table row selections using the Storyboard editor. I have experience with custom callouts in MapKit, but can not figure out how to push a view controller that is defined in a storyboard from the callout. I was going to use [self.navigationController pushViewController:abc animated:YES], however, to do this I need to either get the view controller from the storyboard or initialize a new viewcontroller. I don't have access to the NIB name since there is no NIB name. How do I get access to an instance of a ViewController defined in a storyboard? Is there some way to use the Storyboard editor to wire PUSH Seques to a custom map annotation callout?

Thanks in advance.


Solution

  • You can create segues between view controllers that are programmatically performed by control-dragging from one view controller to the other. Then in the MKMapViewDelegate method, - (void)mapView:annotationView:calloutAccessoryControlTapped:, you can programmatically perform a segue as long as you have given the segue an identifier in the storyboard.

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
    {
        // I've chosen to pass the annotation view as the sender here.
        // I'm assuming this view controller will be configured with data that
        // is backing the annotation view. By passing the view, you will be able
        // to inspect it and it's backing annotation in `prepareForSegue:sender:`
        [self performSegueWithIdentifier:@"ShowSomeViewController" sender:view];
    }