I have a login view. If the login is successfully done, I want my program, navigate to the main window.
I used modal segue, between the login view and main view.
However, after reaching main view, I want to use push segues and unfortunately I'm facing the following exception:
Terminating app due to uncaught exception 'NSGenericException', reason:
'Could not find a navigation controller for segue 'routeList'.
Push segues can only be used when the source controller is managed by an
instance of UINavigationController.'
Here is the functions that I gave the command for "modal segue" in "login controller":
//LoginController.m
- (IBAction)loginTapped:(id)sender {
[self performSegueWithIdentifier:@"login" sender:@{@"foo": @"bar"}];
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"login"])
{
MainController *vc = segue.destinationViewController;
vc.uuid = userUuid;
}
}
Here are the functions that I use to perform "push segue" in the "main controller". I want to perform a push segue here and I face the exception in this part.
//MainController.m
- (IBAction)actionGo:(id)sender {
[self performSegueWithIdentifier:@"routeList" sender:self];
}
In fact, I have a navigation controller before "login view". So why does it couldn't find a "navigation controller"?
If I use modal segue, it works. So why doesn't it work for push segue?
Edit 1 - My storyboard:
Edit 2 - It is suggested to embed main controller into a navigation controller (Click the source controller of the routeList segue and under the Editor menu select Embed In > Navigation Controller). Now, my story board is given below and I'm facing this error now:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[UINavigationController setUuid:]: unrecognized selector sent to
instance 0x17da9df0'
I'm passing a value from login controller to main controller. When I add a navigation controller I couldn't pass this value. How can I pass this value?
Storyboard when MainController is embedded into a navigation controller:
SOLUTION IN MY WORDS:
Thanks to the people that shared their answered in this thread :) I solved the problem. In the navigation controller stack, if I put a modal segue, somehow the link is broken and rest of the views are not part of the navigation controller. So, I made all segues as "push style". Then In the MainController.m I removed the back button as follows:
-(void)viewDidAppear:(BOOL)animated{
[self.navigationItem setHidesBackButton:YES animated:NO];
}