PresViewController: 在 iOS < 6(AutoLayout)上崩溃

这是一个奇怪的崩溃,我得到了。当我按下指向某个 ViewController 的按钮时,会发生崩溃。它撞上的那条线是:

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

坠机痕迹是:

由于未捕获异常“ NSInvalidUnarchive veOperationException”终止应用程序,原因: “无法实例化名为 NSLayoutConstraint 的类” 第一个投掷呼叫堆栈: 3153d6bb 0x3153d4230x314ce0010x3143c3c70x31319c590x3128fc170x3129a2670x3129a1d50x3133959b 0x313383670x840910x374dc3fd 0x31271e070x31271dc30x31271dc10x31271b110x312724490x3127092b 0x312703190x312566950x31255f3b 0x33c9822b 0x375553130x374d84a50x374d836d 0x333c974390x31284cd50x82bb30x71200) 不能实例化名为 NSLayoutConstraint

的类

注意: 这在我的 iPhone4iOS5.1上崩溃了,但在我的 iPhone4S iOS6Beta 2上没有

25374 次浏览

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.

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.

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.

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.