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

本文翻译自:Applications are expected to have a root view controller at the end of application launch

I get the following error in my console: 我在控制台中收到以下错误:

Applications are expected to have a root view controller at the end of application launch 应用程序在应用程序启动结束时应具有根视图控制器

Below is my application:didFinishLaunchWithOptions method: 下面是我的application: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;
}

In Interface Builder, the UITabBarController 's delegate is hooked up to the App Delegate. 在Interface Builder中, UITabBarController的委托连接到App Delegate。

Anyone know how to fix this issue? 有谁知道如何解决这个问题?


#1楼

参考:https://stackoom.com/question/VYXz/应用程序在应用程序启动结束时应具有根视图控制器


#2楼

I came across the same issue but I was using storyboard 我遇到了同样的问题,但我使用的是storyboard

Assigning my storyboard InitialViewController to my window's rootViewController . 将我的storyboard InitialViewController分配给我的窗口的rootViewController

In

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
...
UIStoryboard *stb = [UIStoryboard storyboardWithName:@"myStoryboard" bundle:nil];
self.window.rootViewController = [stb instantiateInitialViewController];
return YES;
}

and this solved the issue. 这解决了这个问题。


#3楼

Replace in AppDelegate 在AppDelegate中替换

 [window addSubview:[someController view]];

to

  [self.window setRootViewController:someController];

#4楼

If you use MTStatusBarOverlay, then you'll get this error. 如果您使用MTStatusBarOverlay,那么您将收到此错误。

MTStatusBarOverlay creates an additional window ([[UIApplication sharedApplication] windows) which doesn't have a root controller. MTStatusBarOverlay创建一个没有根控制器的附加窗口([[UIApplication sharedApplication]窗口)。

This doesn't seem to cause a problem. 这似乎不会导致问题。


#5楼

None of the above suggestions solved my problem. 上述建议都没有解决我的问题。 Mine was this: 我是这样的:

Add: 加:

window.rootViewController = navigationController;

after: 后:

[window addSubview:navigationController.view];

in my appdelegate's 在我的appdelegate中

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

#6楼

On top of "sho" answer, that is correct (fourth parameter of UIApplicationMain should be the name of the main controller), I add some comments. 在“笑”答案之上,这是正确的(UIApplicationMain的第四个参数应该是主控制器的名称),我添加了一些注释。

I have recently changed the 'model' of an app of mine from using MainWindow.xib to construct a window programatically. 我最近改变了我的应用程序的'模型',使用MainWindow.xib以编程方式构建窗口。 The app used an older template that created that MainWindow automatically. 该应用程序使用较旧的模板自动创建MainWindow。 Since I wanted to support a different controller view XIB for iPhone 5, it is easier to choose the right XIB programatically when the App Delegate is created. 由于我想支持iPhone 5的不同控制器视图XIB,因此在创建App Delegate时以编程方式选择正确的XIB更容易。 I removed MainWindow.xib from project as well. 我也从项目中删除了MainWindow.xib。

Problem was, I forgot to fill the fourth parameter in UIApplication main and I FORGOT TO REMOVE MainWindow from "Main Interface" at Project Summary. 问题是,我忘了填写UIApplication main中的第四个参数,我忘记从项目摘要中的“主界面”中删除MainWindow。

This caused a BIG problem: it rendered the harmless warning "Applications are expected to..." on development devices, but when it went to App Store, it broke on consumer phones, crashing because MainWindow was no longer in the bundle! 这引起了一个大问题:它在开发设备上呈现了无害的警告“应用程序应该......”,但是当它进入App Store时,它在用户手机上崩溃,因为MainWindow不在捆绑中而崩溃! I had to request an expedited review for the bugfix. 我不得不要求加快对错误修复的审查。

Another sympthom is that sometimes a white block, like a blank UIView, was sometimes appearing when Settings were changed and app was put in foreground. 另一个问题是,当设置被更改并且应用程序被置于前台时,有时会出现像空白UIView一样的白色块。 In iPhone 5 it was clear that it was an 320x480 block. 在iPhone 5中很明显它是一个320x480块。 Perhaps the missing MainWindow was being created in development mode, using the old size. 也许缺少的MainWindow是在开发模式下使用旧的大小创建的。 I had just found this bug when the first reports of the crash reached the inbox. 当崩溃的第一个报告到达收件箱时,我刚刚发现了这个错误。

Installing the app from App Store instead of from XCode showed that the app indeed crashed, and the MainWindow issue revealed itself on log, so I could see that it was not some special combination of devices+IOS versions. 从App Store而不是从XCode安装应用程序表明应用程序确实崩溃,并且MainWindow问题在日志中显示出来,所以我可以看到它不是设备+ IOS版本的一些特殊组合。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值