2
votes

I have an app which is structured like below.

  1. First the User logs in with his credentials.
  2. Then chooses few selection criteria (ex:Ticket details)
  3. A table view appears and shows the brief details of the ticket.
  4. A push segue from table view based upon the selection will show the detailed view.

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.

1
"A table view appears" -- how are you making it appear? How and where are you adding the navigation controller? Why can't a navigation controller be the initial controller?rdelmar
Hi Thanks for the reply. Site doesnt allow me to enter images (as i dont have the minimum reputations).Can you please drop a initial mail to [email protected] , i will explain you my problem in reply. Expecting your mail. ThanksDinesh Babu

1 Answers

3
votes

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