我在控制台得到以下错误:

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

下面是我的应用程序:didFinishLaunchWithOptions方法:

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

    // Set Background Color/Pattern
    self.window.backgroundColor = [UIColor blackColor];
    self.tabBarController.tabBar.backgroundColor = [UIColor clearColor];
    //self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"testbg.png"]];

    // Set StatusBar Color
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];

    // Add the tab bar controller's current view as a subview of the window
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

在Interface Builder中,UITabBarController的委托被连接到App委托。

有人知道怎么解决这个问题吗?


当前回答

当文件的主窗口所有者时也会出现此错误。Xib设置不正确。

文件的所有者是UIApplication->应用程序委托类的插入对象,窗口出口连接到窗口

其他回答

确保你的“Is Initial View Controller”为你的第一个场景正确设置。

这就是导致错误的原因。

我的第一个视图是MenuViewController,我添加:

MenuViewController *menuViewController = [[MenuViewController alloc]init];
self.window.rootViewController = menuViewController;

在App Delegate方法上:

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

这工作。

这发生在我身上是因为我无意中注释了:

[self.window makeKeyAndVisible];

from

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

如果你使用MTStatusBarOverlay,你会得到这个错误。

MTStatusBarOverlay创建了一个额外的窗口([[UIApplication sharedApplication] windows),它没有根控制器。

这似乎没有引起问题。

在AppDelegate中替换

 [window addSubview:[someController view]];

to

  [self.window setRootViewController:someController];