Fro*_*art 12 cocoa-touch ios swift
我需要从中呈现视图控制器AppDelegate
,所以我编写了以下代码:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let authViewController = storyboard.instantiateViewControllerWithIdentifier("ViewController") as ViewController
if let keyWindow = UIApplication.sharedApplication().keyWindow {
keyWindow.rootViewController = authViewController
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,window
和keyWindow
都是nil
.为什么?
jrt*_*ton 41
如果不使用主界面选项,则需要自己创建窗口:
window = UIWindow(frame:UIScreen.mainScreen().bounds)
Run Code Online (Sandbox Code Playgroud)
Swift 3.0
self.window = UIWindow(frame: UIScreen.main.bounds)
Run Code Online (Sandbox Code Playgroud)
然后使用,调用上面的代码window
.
最后,打电话makeKeyAndVisible()
给窗口.
归档时间: |
|
查看次数: |
7499 次 |
最近记录: |