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

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

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

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


当前回答

我在使用自定义ServiceLocator使用CoreData时得到了这样的错误

let context: NSManagedObjectContext = try self.dependencies.resolve()

//solution
let context: NSManagedObjectContext? = try? self.dependencies.resolve()

其他回答

以上建议没有一个能解决我的问题。我的回答是:

Add:

window.rootViewController = navigationController;

后:

[window addSubview:navigationController.view];

在我的appdelegate中

- (void)applicationDidFinishLaunching:(UIApplication *)application {

在AppDelegate中替换

 [window addSubview:[someController view]];

to

  [self.window setRootViewController:someController];

我也有这个问题。事实证明,当我从左边的对象列表中删除应用程序委托时,我删除了应用程序委托,窗口和TabBarController的连接:)

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

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

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

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

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