0

应用程序运行良好,直到我将 XCode 更新到 4.5 版和 iOS 6 SDK。

应用程序因以下输出而崩溃:

*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',    reason: 'A view can only be associated with at most one view controller at a time! View   <UIView: 0xad397b0; frame = (0 20; 320 460); autoresize = W+H; layer = <CALayer: 0xad39810>> is associated with <UIViewController: 0xad39940>. Clear this association before associating this view with <RootViewController: 0x9e62f00>.'
*** First throw call stack:
(0xda012 0x1ea7e7e 0xd9deb 0xbc9309 0xc605ac 0xc5ca90 0x1661e8e 0x16619b7 0x168c428     0xd980cc 0x1ebb663 0xd545a 0xd96bcf 0xc5be37 0xc5c418 0xc5c648 0xc5c882 0xc5cb2a 0xc73ef5   0xc73fdb 0xc74286 0xc74381 0xc74eab 0xc74fc9 0xc75055 0xd7a3ab 0xbcb92d 0x1ebb6b0 0x405fc0   0x3fa33c 0x3fa150 0x3780bc 0x379227 0x41bb50 0xb9152f 0xa2afe 0xa2a3d 0x807c2 0x7ff44 0x7fe1b 0x2bef7e3 0x2bef668 0xb7b65c 0x2a6b 0x29d1)
libc++abi.dylib: terminate called throwing an exception

应用程序正在添加到窗口登录视图,然后是带有以下代码的标签栏视图:

/* LOGIN VIEW ADD */

[window addSubview:[loginVC view]];
[window makeKeyAndVisible];

/* LOGIN VIEW REMOVE AND ADD TAB BAR CONTROLLER */

[loginVC.view removeFromSuperview];
[window addSubview:[tabBarController view]];
[window makeKeyAndVisible];

应用程序在删除和添加后崩溃。

苹果在 iOS 6 上做了什么?为什么这会崩溃?

4

1 回答 1

0

您不再应该在主窗口中将视图添加为子视图。现在,正确的做法是将您的设置rootControllerUIViewController您想要的,即根目录。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UIViewController *myViewController = [[UIStoryboard storyboardWithName:@"RandomStoryboard" bundle:nil] instantiateInitialViewController];
    window.rootViewController = myViewController;
    return YES;
}

大多数应用程序都可以通过简单的方式做到这一点。如果您的项目中有一个主故事板(在项目文件中设置),它将自动从该故事板实例化初始视图控制器。

于 2012-09-28T16:42:41.583 回答