阅读358 返回首页    go 阿里云 go 技术社区[云栖]


Applications are expected to have a root view controller at the end of application launch

问题:Applications are expected to have a root view controller at the end of application launch

环境:XCode4.2

场景:这种问题多发生在XCode4.2 移植低版本项目时出现。

原因:在iOS5下,应用加载时,需要一个root view controller,在iOS5以下的版本会有MainWindow作为启动文件,iOS5以上没有了。

解决方案:手动创建一个root view controller,在application:didFinishLaunchingWithOptions中添加如下方法,同时为了避免新增加的view对已有的程序产生影响,把ViewController.xib文件的Alpha值设置为0,即完全透明。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // ===========add code===========
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    //self.viewController = [[ViewController alloc] init];
    self.window.rootViewController = self.viewController;
    // ===========add code============

    [self showTabBarController:1];
    [self.window makeKeyAndVisible];
    
	return YES;
}


参考资料:https://stackoverflow.com/questions/7520971/applications-are-expected-to-have-a-root-view-controller-at-the-end-of-applicati

https://alpascual.com/post/2011/10/09/Applications-are-expected-to-have-a-root-view-controller-at-the-end-of-application-launch.aspx



最后更新:2017-04-02 22:16:01

  上一篇:go CSDN精选Android开发博客
  下一篇:go visio 怎么画直线