Question

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.

Was it helpful?

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];
}

OTHER TIPS

I added a button and performed by control dragging it to the view controller. After that I use hidden property of the button to make sure it's hidden. You can't just control dragged a mapview to another view controller. You got to use a button for that. Make sure that you give your segue an identifier.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    [self performSegueWithIdentifier:@"detailSegue" sender:view];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top