92

This is a weird crash I am getting. The crash happens when I press a button that goes to a certain ViewController. The line which it crashes on is:

DestinationInformationViewController *info = [[DestinationInformationViewController alloc] init];
[info setModalTransitionStyle: UIModalTransitionStyleCrossDissolve];
[self presentViewController:info animated:YES completion: nil]; // CRASHES HERE
[info release];

The crash trace is:

*** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint' *** First throw call stack: (0x3758288f 0x35287259 0x37582789 0x375827ab 0x3153d54d 0x3153d6bb 0x3153d423 0x314ce001 0x3143c3c7 0x31319c59 0x3128fc17 0x3129a267 0x3129a1d5 0x3133959b 0x31338367 0x84091 0x374dc3fd 0x31271e07 0x31271dc3 0x31271da1 0x31271b11 0x31272449 0x3127092b 0x31270319 0x31256695 0x31255f3b 0x33c9822b 0x37556523 0x375564c5 0x37555313 0x374d84a5 0x374d836d 0x33c97439 0x31284cd5 0x82bb3 0x71200) terminate called throwing an exception(gdb) Could not instantiate class named NSLayoutConstraint

NOTE: This crashes on my iPhone 4 iOS 5.1 but not on my iPhone 4S iOS 6 Beta 2

MCKapur
  • 9,127
  • 9
  • 58
  • 101

4 Answers4

201

I believe this is an issue with Xcode's new interface builder. Did you happen to build your .xib using Xcode 4.5's interface builder? I've run into this same problem just now, and I think that's the problem. My app runs on iOS 6, but not anything older.

And you need to make sure you turn off Use Auto Layout for your xibs.

That can be done by:

  1. Open your xib.
  2. Go to the File Inspector tab.
  3. Find the Interface Builder Document section on the right toolbar.
  4. Uncheck the Use Auto Layout option.
Mark
  • 7,167
  • 4
  • 44
  • 68
  • 37
    Yeah, you need to make sure you turn off "use auto layout" for your nibs. – Wevah Jun 25 '12 at 23:59
  • Yes, same problem. What to do about it? Should I test it on Xcode 4.4 (That might be the reason, for some strange reason my iPhone 4 iOS 5.1 can run on Xcode 4.5... even though it isn't iOS 6) – MCKapur Jun 26 '12 at 00:00
  • 16
    In the main view of your xib, Interface builder Document section on the right toolbar. – Mark Jun 26 '12 at 00:04
  • For anyone interested, I created a nib file in Xcode 4.5 for an old view controller that setup its view programmatically. I soon realized my new nib wouldn't work in iOS 5, so I deleted the nib file, and started getting a similar error, even thought the new nib file was no longer even in my project! The solution was to rename the .h and .m files, ugh. – Keller Sep 21 '12 at 17:19
  • So umm... how do you get this working WITH autolayout? Isn't it an iOS5 and up feature? – crewshin Sep 21 '12 at 22:43
  • I guess it is only >6. Could have sworn it was 5>. – crewshin Sep 21 '12 at 23:42
  • From the XCode 4.5 release notes: In this Xcode release, Auto Layout is turned on for new user interface documents (storyboards and nib files). Because Auto Layout requires iOS 6.0, using such user interface documents on earlier iOS releases results in a crash or other undefined behavior. 12289644 For your app to run on earlier iOS releases, turn off Auto Layout in its user interface documents. – n13 Sep 30 '12 at 03:24
  • If you don't see that option on the right, make sure the focus on the left is set on the 'storyboard' file. – Gonen Oct 08 '12 at 11:00
  • 2
    Bit of a worry what is happening to quality control at Apple these days. – port5432 Oct 09 '12 at 11:11
43

ScreenShot

I had the same problem when I downloaded new XCode update and IOS6 SDK. Here's how I solved it:

Select the Interface builder file (whether xib or storyboard file) where your error occurs. In assistant editor on the right in XCode, select the first tab from the left, and there is a checkbox for option "Use Autolayout" like on the screenshot above. Uncheck the checkbox.

Jeffrey Bosboom
  • 13,313
  • 16
  • 79
  • 92
Dejan Balaban
  • 461
  • 4
  • 11
4

Nagaraja asks "How to resolve the same if we are not using xib? I ran into exactly this problem. I created a controller with a xib, and then I decided to remove the xib file. The crash did not go away. The problem was that I needed to implement

- (void) loadView

in my controller class. Once I implemented this method the problem got solved.

DDRider62
  • 753
  • 6
  • 17
1

Another possible reason for a crash with presentViewController is having something in the nib connected to a variable that is no longer there - the variable either having it's name changed or it was deleted.

Chris Walken
  • 378
  • 1
  • 9