【发布时间】:2017-01-16 05:50:55
【问题描述】:
我正在以编程方式设置窗口的 rootViewController,如下所示(AppDelegate 的application 方法下的didFinishLaunchingWithOptions):
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootViewController = storyboard.instantiateViewControllerWithIdentifier("loginScreen")
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.makeKeyAndVisible()
if let window = window {
window.rootViewController = rootViewController
}
我是否仍需要进入 Interface Builder 并将该控制器设置为初始视图控制器?我得到Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?
如果我设置了一个入口点,我没有问题并且错误消失了。我想知道以编程方式加载视图的正确方法是什么。以编程方式和通过界面构建器设置 rootViewController 很奇怪。请注意,我是初学者。
【问题讨论】:
-
我的解决方案几乎用完了。我已经检查了这些问题,所以我认为这不是重复的。
-
如果您仍然使用故事板,请忘记代码并在 Interface Builder 中设置条目。
-
我不会使用 Segues,所以以编程方式设置 rootViewController 就可以了。我认为重新设置条目将是最终决定。很奇怪,这就是我问这个的原因。