Reputation: 27
I have an app which is structured like below.
Here I have added a navigation controller for the table view and tried keeping it as the root view controller. Also, I tried having my first view controller as root view folder.
The error msg is:
* Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'TicketDetailSegue'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.' * First throw call stack:
Below is my code on Segue:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"TicketDetailSegue"]) {
UITableViewCell *cell=(UITableViewCell *)sender;
NSIndexPath *ip= [self.tableView indexPathForCell:cell];
Ticket *T=[self.TicketsFinal objectAtIndex:ip.row];
ViewFour *pdvc=(ViewFour *)segue.destinationViewController;
pdvc.ticket=T;
}}
Note: My NavigationController cannot be the initial controller. Can someone suggest a solution? Any help is much appreciated.
Upvotes: 2
Views: 945
Reputation: 104092
The problem is that you present the controller (the one with the prepareForSegue method you posted) that's the navigation controller's root view controller instead of presenting the navigation controller itself, so the navigation controller doesn't make it into your controller hierarchy. Your submit method in ViewTwo should look like this:
-(IBAction)Submit
{
UINavigationController *nav =[self.storyboard instantiateViewControllerWithIdentifier:@"TicketsListNav"];
TicketListViewController *third = (TicketListViewController *)nav.topViewController;
// other stuff here
[self presentViewController:nav animated:YES completion:nil];
}
Upvotes: 3