I posted a question earlier today regarding reacting to the receipt of a push notification, whereby I needed to drill down from one view to another. This question was answered, however I have now moved on to another requirement for reacting to push notifications, whereby I need to drill down to a third level in the navigation stack.
Below is a mockup of my view hierarchy, where on receipt of the push notification I want to drill down to the view titles "Third View".
From the answer to my previous question, I am able to drill down to "Second View", however when I try to perform the segue to push "Third View" on to the stack, I get the same type of error as per my previous question:
Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'Admin'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
In my AppDelegate, when I receive the notification I select the required tab then:
UINavigationController *navController = (UINavigationController*)[_tabBarController selectedViewController];
NHProfileViewController *profileViewController = navController.viewControllers[0];
[profileViewController displayAdminWebViewForPushNotification];
Then in profileViewController (First View) displayAdminWebViewForPushNotification:
_displayAdminForPushNotification = YES;
[self performSegueWithIdentifier:@"Settings" sender:self];
where "Settings" is "Second View" in the image above.
Then in prepareForSegue:
if ([segue.identifier isEqualToString:@"Settings"])
{
NHSettingsTableViewController *settingsViewController = segue.destinationViewController;
if (_displayAdminForPushNotification)
{
[settingsViewController displayAdmin];
_displayAdminForPushNotification = NO;
}
}
Up to this point all is fine, however as soon as I hit [settingsViewController displayAdmin]:
- (void)displayAdmin
{
[self performSegueWithIdentifier:@"Admin" sender:self];
}
it crashes. I have done some debugging and at this point settingsViewController does not have a navigation controller (hence the crash/error message). This I don't understand as "First View" is embedded in a navigation controller.
Your performing the third segue to early -- the second segue isn't even done so it has no navigationController.
delay it by using this method to perform action after segue:
How to execute some code after a segue is done?
or use viewWillAppear!