166

我对此很陌生。我按照 Apple 的 iPhone 项目“HelloWorld”教程一步一步来。我在 iPhone 5.0 模拟器中运行它,它崩溃了:

2012-11-02 14:46:06.782 HelloWorld[9880:c07] * 由于未捕获的异常“NSInvalidUnarchiveOperationException”而终止应用程序,原因:“无法实例化名为 NSLayoutConstraint 的类”*第一次抛出调用堆栈:(0x14a2052 0xea2d0a 0x144aa78 0x144a9e9 0xfafd70x 0x32f6b7 0x23036d 0xd7e2c 0xd83a9 0xd85cb 0x38a73 0x38ce2 0x38ea8 0x3fd9a 0x10be6 0x118a6 0x20743 0x211f8 0x14aa9 0x138cfa9 0x14761c5 0x13db022 0x13d990a 0x13d8db4 0x13d8ccb 0x112a7 0x12a9b 0x1fed 0x1f15 0x1) terminate called throwing an exception(lldb)

有人可以告诉我出了什么问题吗?我正在使用 Xcode 4.5。

4

4 回答 4

576

默认情况下,当您在 Xcode 4.5 中创建新的 iOS 项目时,您的故事板或 XIB 设置为使用 Autolayout,这是 iOS 6.0 中的新功能。该类NSLayoutConstraint是 Autolayout 系统的一部分,在旧版本的 iOS 中不存在。

如果您想将您的应用程序部署到旧版本的 iOS,您需要更改您的故事板或 XIB 以使用自动布局。这是文件检查器中的一个复选框:

关闭自动布局

于 2012-11-02T19:18:37.090 回答
21

Your Xib file (Interface builder file) contains AutoLayout elements, which iOS 5 does not support.

In Xcode, go to your .xib file(s), and for each one, turn off AutoLayout. There should be a checkbox on the left hand side saying "Use AutoLayout", uncheck it and try again. (This is under the first tab in the left hand side inspector, when you have File's owner) selected.

于 2012-11-02T19:19:28.470 回答
8

当我在处理一个我想更新的旧项目时,我偶然发现了这个错误。我选择了“使用自动布局”复选框开始使用约束,但忘记将我的部署目标设置更新为 iOS 6。

于 2012-12-09T09:40:08.483 回答
7

您需要在 iPhone 6.0 模拟器中运行它。你的错误:

* Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint' *

建议您使用自动布局,它仅适用于 iOS 6。

于 2012-11-02T19:19:04.660 回答