13
votes

enter image description here

On my storyboard (shown above), I have a ViewController which holds an MKMapView with annotations. These annotations hold a disclosure icon, which when tapped, should navigate the user to another ViewController. To do so I've created a push segue between the view controllers. I've then given it an identifier of 'showDetail' and implemented the following code.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    [self performSegueWithIdentifier:@"showDetail" sender:self];
}

However I get the following error.

Could not find a navigation controller for segue 'showDetail'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'

Where am I going wrong? I have tried changing my source UIViewController to a UINavigationController, but the view then just displays as a black screen.

3
Can you post a screenshot of your storyboard with both ViewControllers? - Mariusz
@Mariusz question updated! Thank you. - Jonathan
Try to embed your target ViewController in a NavigationController and drag your segue from the MapViewController to the NavigationController. - Mariusz

3 Answers

40
votes

Simplest way to do this is to select the View controller you want to be the root of your navigation hierarchy and choose

Editor > Embed In > Navigation Controller

This creates the new navigation controller and hooks up everything up for you.

38
votes

You actually have to set your UIViewController as the root controller of a UINavigationController (or pushed through from a view controller w/ a navcontroller). To do that

  • Drag a new navigation controller into your storyboard - it will by default be attached to a tableview controller
  • Delete the tableview controller Right click on the navgiation controller, and connect the "Root View Controller" property to your existing view controller
  • Move the entry point arrow from your view controller to the root view controller
0
votes

check this steps: 1. to click connection between two view controller. 2. click attribute inspector 3. set identifier to "showDetail". 4. save and run.