问题: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;
}