presentViewController: crash on iOS <6 (AutoLayout)

Objective CIosXcodeCrashStack Trace

Objective C Problem Overview


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

Objective C Solutions


Solution 1 - Objective C

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.

Solution 2 - Objective C

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.

Solution 3 - Objective C

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.

Solution 4 - Objective C

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMCKapurView Question on Stackoverflow
Solution 1 - Objective CMarkView Answer on Stackoverflow
Solution 2 - Objective CDejan BalabanView Answer on Stackoverflow
Solution 3 - Objective CDDRider62View Answer on Stackoverflow
Solution 4 - Objective CChris WalkenView Answer on Stackoverflow