1

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.

User97693321
  • 3,336
  • 7
  • 45
  • 69
aullman
  • 23
  • 3
  • 1
    Just found a link that explained how to Instantiate a ViewController in Storyboard: UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]]; myViewController *myVC = [storyboard instantiateViewControllerWithIdentifier:@"myViewController"]; This worked. I was able to push the view controller once I instantiated it using this code. My problem is solved. – aullman Jan 22 '12 at 05:15
  • Please add your solution as an answer to the question, and then accept your answer. It's ok to accept your own answer to your question. – rob mayoff Jan 22 '12 at 05:53

2 Answers2

1

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];
}
Perception
  • 79,279
  • 19
  • 185
  • 195
Caspian
  • 11
  • 1
  • how do I use this and pass some data across to the segue? I tried using prepareForSegue or even shouldPerformSegue ...but seems to by pass these two methods – user1372829 Dec 19 '12 at 16:47
1

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];
}
Mark Adams
  • 30,776
  • 11
  • 77
  • 77