358
技術社區[雲棲]
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;
}
最後更新:2017-04-02 22:16:01