無我需要從AppDelegate
現在視圖控制器,所以我寫了下面的代碼:爲什麼窗口是在AppDelegate中
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let authViewController = storyboard.instantiateViewControllerWithIdentifier("ViewController") as ViewController
if let keyWindow = UIApplication.sharedApplication().keyWindow {
keyWindow.rootViewController = authViewController
}
不幸的是,window
和keyWindow
都是nil
。爲什麼?
何時執行此代碼? – jrturton 2014-11-23 20:23:49
@jrturton這是代碼在'func應用程序中執行(應用程序:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) - > Bool'函數 – FrozenHeart 2014-11-23 20:25:59
好吧,在這個函數中,手動創建了一個,或者您已將故事板或xib設置爲啓動界面。你做到了嗎? – jrturton 2014-11-23 20:27:29