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

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

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

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


当前回答

ARC更改:

改变

@synthesize window;

而不是

@synthesize window=_window;

其他回答

确保在应用程序委托中有这个函数。

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

确保didFinishLaunchingWithOptions返回YES。如果你碰巧删除了'return YES'行,这将导致错误。这个错误在故事板用户中可能特别常见。

我升级到iOS9,开始出现这个错误。我能够修复它,但添加以下代码到- (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow *window in windows) {
    if(window.rootViewController == nil){
        UIViewController* vc = [[UIViewController alloc]initWithNibName:nil bundle:nil];
        window.rootViewController = vc;
    }
}

移动setRootViewController:从didFinishLaunchingWithOptions:到awakeFromNib:解决了这个问题在我的空项目。

这发生在我身上。通过编辑.plist文件解决。 指定Main nib文件基名。(应该是MainWindow.xib)。 希望这能有所帮助。

我也有这个问题。我让我的项目在xcode4.2.1中运行。我已经看了上面所有的评论,但没有人对我来说很酷。过了一会儿,我发现我注释了一段代码。

//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

然后我取消了评论。我一切都好。 希望这对你们有帮助。