为什么窗口是在AppDelegate中
无我需要从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
。为什么?
您需要在不使用主界面选择自己创建的窗口:
window = UIWindow(frame:UIScreen.mainScreen().bounds)
雨燕3.0
self.window = UIWindow(frame: UIScreen.main.bounds)
然后调用上面的代码,使用window
。
最后,在窗口上拨打makeKeyAndVisible()
。
我不想自动加载初始视图控制器,因为我需要手动提供授权视图控制器或主视图控制器 – FrozenHeart 2014-11-23 20:41:45
那么你的问题并不清楚!更新即将到来... – jrturton 2014-11-23 20:48:23
你是对的,对不起 – FrozenHeart 2014-11-23 20:52:13
何时执行此代码? – 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