0

可能重复:
应用程序在应用程序启动结束时应该有一个根视图控制器

我的应用程序使用 uitabbarcontroller 和几个导航控制器。它在模拟器和真实设备上运行正常。然而,让我感到不安的是我在控制台中启动应用程序时收到的这条消息。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]));
    }
}

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

4

1 回答 1

0

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

UINavigationController *nav = (UINavigationController *)self.window.rootViewController;
于 2013-01-18T16:42:57.167 回答