【问题标题】:Xcode 4.5 Black Screen or Exception: 'A view can only be associated with at most one view controller at a time!'Xcode 4.5 黑屏或异常:“一个视图一次只能与一个视图控制器关联!”
【发布时间】:2012-10-02 03:37:05
【问题描述】:

在升级到 Xcode 4.5 之前,我有一个现有的 iPhone 应用程序在 Xcode 4.0 中运行良好。升级后,现在我在 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 编程相当陌生(虽然对一般编程并不陌生),而且我真的在为此苦苦挣扎。非常感谢任何帮助。

【问题讨论】:

    标签: objective-c xcode cocos2d-iphone


    【解决方案1】:

    首先,删除

    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-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    相关资源
    最近更新 更多