ios NSInvalidUnarchiveOperationException:无法实例化名为 NSLayoutConstraint 的类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13201586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:04:25  来源:igfitidea点击:

NSInvalidUnarchiveOperationException: Could not instantiate class named NSLayoutConstraint

objective-ciosautolayout

提问by user1703590

I am very new to this. I followed Apple's tutorial step by step for the iPhone project "HelloWorld". I ran it in the iPhone 5.0 simulator and it crashed:

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

2012-11-02 14:46:06.782 HelloWorld[9880:c07] * Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint' *First throw call stack: (0x14a2052 0xea2d0a 0x144aa78 0x144a9e9 0x32f7d7 0x32f9af 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)

2012-11-02 14:46:06.782 HelloWorld[9880:c07] * 因未捕获的异常“NSInvalidUnarchiveOperationException”而终止应用程序,原因:“无法实例化名为 NSLayoutConstraint 的类”*第一次抛出调用堆栈:(0x14a205204a04a37x704a04a304a04a37a304a37 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)终止叫做抛出异常(LLDB)

Can someone please tell me what went wrong? I'm using Xcode 4.5.

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

回答by rob mayoff

By default, when you create a new iOS project in Xcode 4.5, your storyboard or XIB is set to use Autolayout, which is a new feature in iOS 6.0. The NSLayoutConstraintclass is part of the Autolayout system, and it doesn't exist in older versions of iOS.

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

If you want to deploy your app to an older version of iOS, you need to change your storyboard or XIB to notuse Autolayout. It's a checkbox in the File Inspector:

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

turning off autolayout

关闭自动布局

回答by WDUK

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

您的XIB文件(界面生成文件)包含自动版式元素,它的iOS 5也没有支持。

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.

在 Xcode 中,转到您的 .xib 文件,并为每个文件关闭 AutoLayout。左侧应该有一个复选框,上面写着“使用自动布局”,取消选中它并重试。(这是在左侧检查器的第一个选项卡下,当您选择了文件的所有者时)。

回答by jbryant

I stumbled into this error when I was working on an older project I wanted to update. I had selected the "Use Autolayout" checkbox to start working with constraints, but had forgotten to update my Deployment Target setting to iOS 6.

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

回答by yeesterbunny

You need to run it in iPhone 6.0 simulator. Your error:

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

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

Suggests that you are using autolayout, which only works on iOS 6.

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