无我需要从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