I'm creating my managedObjectContext in GameAppDelegate and passing it to my first ViewController (GameViewController) which isn't embedded in a UINavigationController, i want to pass then my managedObjectContext to my next view which is embedded in a navigationController. this is what i tryed to do so far in my prepareForSegue
:
UINavigationController *navController =(UINavigationController *)segue.destinationViewController;
((PickTypeViewController *)navController.viewControllers[0]).managedObjectContext=managedObjectContext;
but then I get the following error:
Game[17878:c07] Uncaught exception: Could not find a navigation controller for segue 'Play'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.
why is this happening
Exactly as the error message says: the source controller (GameViewController) needs to be managed by UINavigationController if you want to use push segue from GameViewController.
You need to embed UINavigationController into GameViewController, not the second view controller. If you want to hide the navigation bar in the GameViewController, you can do so: iPhone hide Navigation Bar only on first page
After that, you will need to modify your prepareForSegue method, especially the part where you got the segue.destinationViewController
. It will give you directly the PickTypeViewController instance.
PickTypeViewController *pickTypeViewController = (PickTypeViewController *)segue.destinationViewController;