【问题标题】:iOS App Crashes in didFinishLaunchingWithOptions due to IBOutlet由于 IBOutlet,iOS 应用程序在 didFinishLaunchingWithOptions 中崩溃
【发布时间】:2017-04-07 12:00:23
【问题描述】:

在我的 iOS 应用程序中,我有一个带有 2 个用于登录的文本字段的初始视图控制器。 如果我在调试模式下运行应用程序,代码编译良好,我可以看到我在主情节提要上设置的初始视图控制器。

相反,如果我尝试在 Release 中运行代码,应用程序会崩溃,因为没有设置插座。

2017-04-07 13:55:53.422 Sahin Fruit[40068:1230157] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fb5e2e0a450> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key emailTextField.'

为了克服这个问题,我尝试以编程方式在 AppDelegate 中设置初始 VC,但没有结果,应用程序仍然崩溃。有什么想法吗?

    self.window = UIWindow(frame: UIScreen.main.bounds)
    let initialViewController = UIStoryboard.viewControllerWithIdentifier(Main.loginVC.rawValue, storyBoardName: .Main)
    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()

P.S:我在 Release 中关闭了优化,看看是否有帮助也没有结果。

【问题讨论】:

  • 你的初始VC有问题,检查一次emailTextField是否连接
  • emailTextField 肯定是连接的,否则在 debug 中不起作用 =)
  • 保证一次......
  • 在 initWithCoder 阶段使用键值编码。实例化具有相应情节提要资源的视图控制器时出现问题。

标签: ios swift storyboard initialization appdelegate


【解决方案1】:

这是因为您必须在情节提要中复制 ViewController 并为其分配不同的类。只需右键单击 ViewController 顶部的第一个方框(具体名称忘记了),您的额外插座将显示为yellow color triangle, just delete it,您的项目将正常构建。

【讨论】:

    【解决方案2】:

    您有一个旧插座,您已从代码中删除但仍连接在界面构建器中

    【讨论】:

    • 看到这个有问题的In opposite if i try to run the code in Release the app crashes calming that the outlet are not set不在emailTextField is connected for sure, otherwise it would not work in debug中
    【解决方案3】:

    检查您在情节提要中对您的网点的引用,其中一个可能引用了一个不再存在的属性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-02
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多