奇怪的控制台消息 - 应用程序窗口应在应用程序启动结束时具有根视图控制器

时间:2013-01-18 16:18:06

标签: ios appdelegate

  

可能重复:
  Applications are expected to have a root view controller at the end of application launch

我的应用使用uitabbarcontroller和几个导航控制器。它在模拟器和真实设备上运行正常。然而,让我感到不安的是这条消息,我在app中启动了app。Application windows are expected to have a root view controller at the end of application launch

我用谷歌搜索了,但我无法找到答案。 强制appDelegate didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    [defaults setBool:FALSE forKey:@"loggedIn"];
    [defaults setInteger:0 forKey:@"token"];
    [defaults synchronize];

    _window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"app_bg.png"]];

 return YES;
}

我的main.m代码

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

如果有人可以帮助我,我会很高兴:)谢谢!

1 个答案:

答案 0 :(得分:0)

尝试在didFinishLaunchingWithOptions中设置窗口的根视图控制器。如果是导航控制器,请输入:

UINavigationController *nav = (UINavigationController *)self.window.rootViewController;