1

当应用程序被激活时,我正在创建一个文件。基于该文件的存在,加载不同的视图。

我正在尝试的是

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    if(condition true)
    {
        //[window addSubview:viewController.view];
        [self.window setRootViewController:viewController];
        [window makeKeyAndVisible];
        return YES;
    }else{
        //[window addSubview:signViewController.view];
        [self.window setRootViewController:secondViewController];
        [window makeKeyAndVisible];
        return YES;
    }

   // return YES;
}

我得到的错误是Application windows are expected to have a root view controller at the end of application launch

4

3 回答 3

1

在使用它之前,您应该首先alloc和您的视图控制器。init

if(condition true)
{
    //[window addSubview:viewController.view];
    viewController = [[ViewController alloc] init];
    [self.window setRootViewController:viewController];
    [window makeKeyAndVisible];
    return YES;
}else{
    //[window addSubview:signViewController.view];
    secondViewController = [[SecondViewController alloc] init];
    [self.window setRootViewController:secondViewController];
    [window makeKeyAndVisible];
    return YES;
}
于 2012-11-29T12:09:32.413 回答
0

检查您是否有视图控制器的 alloc 和 init。使用 viewController=[[ViewControllerName alloc]init];

当我的 viewController 未分配时,我得到了同样的错误。

于 2012-11-29T12:13:19.410 回答
0

写吧

[window makeKeyAndVisible];
    return YES;

else之后或之前}

于 2012-11-29T11:47:58.517 回答