我正在尝试创建一个应用程序,该应用程序使用 cocos2d 作为主屏幕,并使用 UINavigationController 来显示某些表格和信息。我使用此代码尝试将 UINavigationController (设置)插入 View
UINavigationController *controller = [[UINavigationController alloc] init];
Settings *newTableViewController = [[Settings alloc] init];
[controller pushViewController:newTableViewController animated:YES];
这段代码在CCLayer中执行,Settings是一个UINavigationController。
我收到此错误
*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“不支持推送导航 Controller ”
这是否意味着我无法将 NaviagationController 推送到 CCLayer 中? 请帮忙。
最佳答案
您不能“将 View Controller 推送到 CCLayer”。您使用 cocos2d 所做的所有操作都发生在一个 OpenGL View 中。
如果您确实想做这样的事情,您可以更改应用程序 Root View Controller 的创建。让您的应用程序 View Controller 成为 UINavigationController 而不是 UIViewController 的子类,然后只需从应用程序委托(delegate)中获取 rootViewController 并在需要时将任何其他 View Controller 推送/弹出到它。无论如何,我不认为这是一个好主意。
关于您的异常,我假设您的 Settings 类是 UINavigationController 的子类。您想要推送到导航 Controller 的所有 Controller 都必须从 UIViewController 派生,而不是 UINavigationController。
关于uinavigationcontroller - 在CCLayer中添加UINavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13617221/