【问题标题】:Do I still need to set the entry point? (Initial view controller)我还需要设置入口点吗? (初始视图控制器)
【发布时间】:2017-01-16 05:50:55
【问题描述】:

我正在以编程方式设置窗口的 rootViewController,如下所示(AppDelegateapplication 方法下的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 就可以了。我认为重新设置条目将是最终决定。很奇怪,这就是我问这个的原因。

标签: ios swift2


【解决方案1】:

请在控制器属性中勾选“是初始视图控制器”,然后清理并运行。 如果还存在,请试试这个

   UIApplication.sharedApplication().keyWindow?.rootViewController = viewController;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 1970-01-01
    • 2012-09-09
    • 1970-01-01
    相关资源
    最近更新 更多