Question

I am trying to create an app that uses cocos2d for the homescreen, and a UINavigationController for some tables and information. I use this code to try to push a UINavigationController (Settings) into view

UINavigationController *controller = [[UINavigationController alloc] init];
Settings *newTableViewController = [[Settings alloc] init];
[controller pushViewController:newTableViewController animated:YES];

This code is executed in a CCLayer, and Settings is a UINavigationController.

I get this error

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

Does this mean that I can't push a NaviagationController into a CCLayer? Please Help.

Was it helpful?

Solution

You cannot "push view controller to the CCLayer". All that you are doing using cocos2d takes place inside one OpenGL view.

If you really want to do something like this, you can change creation of the application's root view controller. Make your application view controller a subclass of UINavigationController instead of UIViewController, then just get rootViewController from your app delegate and push/pop any other view controller to it whenever you want. Anyway, I don't think, that it is a good idea.

About your exception I assume that your Settings class is a subclass of UINavigationController. All the controllers that you want to push to the navigation controller must be derived from UIViewController, not UINavigationController.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top