sapatos
sapatos

Reputation: 1304

StoryBoard fails to push segue with Could not find a navigation controller for segue

enter image description here

I have a UIViewController with a container view within it. Within the container view I have embedded a UITableViewController called CategoryTableViewControler.

CategoryTableViewControler loads up the data for displaying the rows and on clicking a cell it pushes a new CategorySecondViewController using

         [self performSegueWithIdentifier:@"CatOneToTwo" sender:self];

When I attempt to do this I get an error:

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'CatOneToTwo'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'

I understand from the forums that this is because of a missing UINavigationController, however this is present. I'm guessing in this case that the first CategoryTableViewController within the Container view does not have access to the NavigationController.

I found the following code to prove this which is in CategoryTableViewController:

    // Perform Segue
if (self.navigationController.visibleViewController == self) {
    [self performSegueWithIdentifier:@"CatOneToTwo" sender:self]; //<<does not get here
}

So question is how do I access the NavigationController here?

As you can see from the image CategorySecondViewController will be doing a similar thing with CategoryThirdViewController as well so I need something that will handle the three levels of pushed scenes.

Upvotes: 1

Views: 1246

Answers (1)

RTasche
RTasche

Reputation: 2644

The problem is that the segue is connected to your view controller containing the container view and not to the UITableViewController inside. You could implement UITableViewDatasource and UITableViewDelegate in your UIViewController to handle tablew view content and remove the extra table view controller.

Upvotes: 1

Related Questions