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

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

下面是我的应用程序: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委托。

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


当前回答

这个Swift 2解决方案对我来说很有效:

在AppDelegate -> didFinishLaunchingWithOptions中插入下面的代码

self.window!.rootViewController = storyboard.instantiateViewControllerWithIdentifier("YourRootViewController") as? YourRootViewControllerClass

其他回答

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

[self.window makeKeyAndVisible];

from

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

尝试将选项卡栏控制器的IBOutlet连接到接口生成器中的根视图,而不是

self.window.rootViewController = self.tabBarController;

但实际上我还没见过这样的错误。

在使用XCode 4.6.3和iOS 6.1将我的UI替换为Storyboard后收到相同的错误

通过清除AppDelegate中的didFinishLaucnhingWithOptions中的所有代码来解决这个问题

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

选择你的“窗口”在你的Nib文件 在“属性检查器”中选择“启动时可见”

手动创建nib文件时会发生这种情况。 这个修复工作于常规的nib模式-不是故事板模式

我也有同样的问题。如果你像我一样“从零开始”构建一个基于窗口的应用程序,你需要做以下工作:(注意,这些是Xcode 4.2的步骤。)

0. 确保你的应用委托符合UIApplicationDelegate协议。

例如,假设我们的委托名为MyAppDelegate。在MyAppDelegate.h中,我们应该有这样的东西:

@interface MyAppDelegate : 
    NSObject <UIApplicationDelegate> // etc...

1. 在main.m中指定应用程序委托

例如,

#import "MyAppDelegate.h"

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

2. 创建一个主窗口界面文件。

为此,右键单击项目并选择新建文件。从那里,选择窗口从iOS ->用户界面部分。

将文件添加到项目后,转到项目的摘要(左键单击项目;点击总结。)在iPhone/iPod部署信息下(如果你喜欢的话,还有相应的iPad部分),在“主界面”组合框中选择你的新界面文件。

3.在接口编辑器中将它们全部连接起来

在文件列表中选择接口文件以调出接口编辑器。

确保Utilities窗格是打开的。

通过从“实用工具”窗格中的“对象”列表中拖动一个对象到窗口对象的上方或下方的空间中添加一个新对象。选择对象。单击Utilities窗格中的Identity检查器。将Class更改为应用程序的委托(本例中为MyAppDelegate)。

调出MyAppDelegate的连接检查器。将窗口出口连接到接口文件中已经存在的窗口。

单击左边的File's Owner,然后单击Utilities窗格中的Identity检查器。将类更改为UIApplication

为File's Owner调出连接检查器。将委托出口连接到MyAppDelegate对象。

4. 最后,也是非常重要的一点,单击接口文件中的Window对象。打开Attributes检查器。确保选中“发射时可见”。

这就是我要让它为我工作所做的一切。好运!