30

* Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '* -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (NSLayoutConstraint)'

I have a very simple app

One view has one button

I Control Click and dragged the button to a second view and selected MODAL

When I run it in the simulator, everything works

When i run it in my iPad running iOS 5.1.1, it crashes with the error above. I have no idea why and there is no code.

James Webster
  • 31,873
  • 11
  • 70
  • 114
Cocoa Dev
  • 9,361
  • 31
  • 109
  • 177
  • Refer to [http://stackoverflow.com/questions/11198981/presentviewcontroller-crash][1] [1]: http://stackoverflow.com/questions/11198981/presentviewcontroller-crash – Pratik Velani Sep 24 '12 at 09:07

2 Answers2

79

This is occuring because you are using Xcode 4.5 (or previously the beta) which uses "auto layout" by default. Auto layout is only available on iOS 6 so you will get a runtime error on previous iOS versions.

You can fix this by opening your Storyboard, opening the Utilities pane, and disabling the "Use Autolayout" checkbox in the first tab/section:

enter image description here

For regular non-storyboard nibs, select the top-level view to access this option.

Mike Weller
  • 45,401
  • 15
  • 131
  • 151
  • Thanks. I would never have found this. – Cocoa Dev Jun 18 '12 at 19:18
  • @Jignesh: This is a well upvoted answer already, and your edit serves better as a comment (or even an answer in it self)I'll instead add your edit text as a comment to the answer. – Avada Kedavra Oct 02 '12 at 16:45
  • From Jignesh's edit *"When I solved my problem I had to uncheck `Use Autolayout` on `nib file` that caused problem for me"*: "You can fix this by opening your Storyboard or any nib file that is causing problem, opening the Utilities pane, and disabling the "Use Autolayout" checkbox in the first tab/section" – Avada Kedavra Oct 02 '12 at 16:46
  • My iOS deployment target is 4.3 and I used Autolayout for some views but xcode didn't warn me about this at all. We shouldn't even be able to build an app that has such settings! Thank you apple... – Alexis Oct 31 '12 at 13:03
  • Well, technically you may have an autolayout view which is only used on iOS 6 and later. So it is a legitimate use case to have autolayout enabled even with a deployment target of < 6.0 – Mike Weller Oct 31 '12 at 16:16
  • Okay, I did as mentioned in Answer and now the error is solved but I have a search bar in a view controller which is positioned on top, but when I run the app the search bar is at the bottom of view :\. What now? Please help. – Abdullah Umer Mar 13 '13 at 20:54
5

In Your Xib-> Identity and type ->Interface Builder Document -> uncheck useAutoLayout check box,this is the new feature with Ios6

Appsunic
  • 192
  • 1
  • 10