应用程序应该添加rootViewController

时间:2012-11-29 11:44:01

标签: iphone objective-c ios uiapplicationdelegate

我在激活应用程序时创建了一个文件。在此基础上,该文件的存在会加载不同的视图。

我正在尝试

- (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

3 个答案:

答案 0 :(得分:1)

在使用视频控制器之前,首先应allocinit

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;
}

答案 1 :(得分:0)

写一下

[window makeKeyAndVisible];
    return YES;

其他之后或}之前

答案 2 :(得分:0)

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

我的viewController未分配时出现同样的错误。