2

在升级到 Xcode 4.5 之前,我有一个在 Xcode 4.0 中运行良好的现有 iPhone 应用程序。升级后,现在我在 iPhone/iPad 4.3 模拟器中运行时出现黑屏,并在运行 iPhone/iPad 6.0 模拟器时出现以下异常。

Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View <CCGLView: 0x8c7f380; frame = (0 0; 320 480); layer = <CAEAGLLayer: 0x8c7f670>> is associated with <CCDirectorDisplayLink = 0x994c7f0 | Size: 320 x 480, view = <CCGLView: 0x8c7f380; frame = (0 0; 320 480); layer = <CAEAGLLayer: 0x8c7f670>>>. Clear this association before associating this view with <RootViewController: 0x8c7ef00>.'

该应用程序使用 Cocos2D 2.0,基于网上找到的教程非常简单。没有 XIB 文件。一切都以编程方式完成。

这些是导致 6.0 模拟器中异常的行(来自 IOS6TestAppDelegate.m):

viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
[enter link description here][1]viewController.wantsFullScreenLayout = YES;

如果这些行被注释掉,那么 6.0 模拟器也会显示黑屏,而不是常规的菜单屏幕。

我在网上搜索了这方面的解决方案并尝试了很多方法,但一直无法取得进展。我对 iPhone 编程相当陌生(虽然对一般编程并不陌生),而且我真的在为此苦苦挣扎。我真的很感激任何帮助。

4

1 回答 1

3

一、删除

viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;

然后更换

[window setRootViewController:viewController];

if( ! [director enableRetinaDisplay:YES] )
    CCLOG(@"Retina Display Not supported");

// Create a Navigation Controller with the Director
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:director];
navController.navigationBarHidden = YES;
NSString *reqSysVer = @"6.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
    [window setRootViewController:navController];
} else
{
    [window addSubview: navController.view];
}

应该这样做!

于 2012-10-02T04:18:19.773 回答