ChatGPT解决这个技术问题 Extra ChatGPT

NSInvalidUnarchiveOperationException: Could not instantiate class named NSLayoutConstraint

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:

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)

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

You have to turn off Autolayout feature in xib/storyboard

r
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 NSLayoutConstraint class is part of the Autolayout system, and it doesn't exist in older versions of iOS.

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

https://i.stack.imgur.com/s0orB.gif


I used ScreenFlow for capture and cropping. I used Photoshop to turn the .mov into a .gif.
This applies for xib's too!
Doing this disables view rotation from portrait to landscape even having the methods implemented. How did you solve the issue if you still want the rotation to take place? Thanks in advance, and ... nice gif ^^
@robmayoff thanks for the gif and the perfect answer. my issue got solved in a second. :)
I liked this so I created my own for exception breakpoints. rsaunders.co.uk/2013/06/add-exception-breakpoint.html
W
WDUK

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.


j
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.


y
yeesterbunny

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

* 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.


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now