閱讀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 怎麼畫直線