iOS 9出现错误Applications are expected to have a root view controller at the end of application launch

今天在xcode7上试了一个老项目,装到iOS9出现闪退然后提示这个
Applications are expected to have a root view controller at the end of application launch

百度一下发现说的情况都不符合,赶紧上stackoverflow找到一个答案解决问题。

If you have already set the rootViewController of your self.window in you app delegate and still getting this error at runtime, then you probably have more than one window in your UIApplication one of which may not have a rootViewController associated. You can loop through your app windows and associate an empty viewController to its rootViewController to fix the error you are getting.

Here’s a code that loops through the app windows and associates an empty ViewController to the rootViewController if a window is missing it.

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

意思就是应用里有多个UIWindow对象而且有的UIWindow没有设置rootViewcontroller,这时设置一个空Viewcontroller就行。也许是iOS9禁止了没有设置rootViewcontroller的UIWindow所以出现了这样的情况。

参考:http://stackoverflow.com/a/32663560
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值