在Swift 4启动屏幕后如何转到视图控制器?

时间:2018-10-13 09:57:58

标签: swift xcode

我正在尝试启动一个应用程序。我得到了初始屏幕,但是随后我将main指向了一个名为LoginController.xib的自定义视图控制器。因此,在启动屏幕之后,我崩溃了,错误提示:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x7fed19c036d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'

是否需要将主屏幕指向Main.storyboard?我该如何工作?

1 个答案:

答案 0 :(得分:0)

如果您的ViewController位于情节提要中,则可以将其标记为初始视图控制器,并使用此情节提要设置主界面,但是如果您的ViewController具有nib文件(.xib),则将主界面设置为空并将窗口根视图设置为您的viewController

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    window = UIWindow(frame: UIScreen.main.bounds)
    let vc = LoginController()
    window?.rootViewController = vc
    window?.makeKeyAndVisible()
    return true
}

enter image description here