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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11198981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:58:05  来源:igfitidea点击:

presentViewController: crash on iOS <6 (AutoLayout)

objective-ciosxcodecrashstack-trace

提问by MCKapur

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:

这是我遇到的一个奇怪的崩溃。当我按下转到某个 ViewController 的按钮时会发生崩溃。它崩溃的线路是:

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

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

注意:这会在我的 iPhone 4 iOS 5.1 上崩溃,但不会在我的 iPhone 4S iOS 6 Beta 2 上崩溃

回答by Mark

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.

我相信这是 Xcode 的新界面构建器的问题。您是否碰巧使用 Xcode 4.5 的界面构建器构建了 .xib?我刚才遇到了同样的问题,我认为这就是问题所在。我的应用程序在 iOS 6 上运行,但不是更旧的。

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

而且您需要确保关闭Use Auto Layoutxibs

That can be done by:

这可以通过以下方式完成:

  1. Open your xib.
  2. Go to the File Inspectortab.
  3. Find the Interface Builder Documentsection on the right toolbar.
  4. Uncheck the Use Auto Layoutoption.
  1. 打开你的xib。
  2. 转到File Inspector选项卡。
  3. 找到Interface Builder Document右侧工具栏上的部分。
  4. 取消选中该Use Auto Layout选项。

回答by Dejan Balaban

ScreenShot

截屏

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

当我下载新的 XCode 更新和 IOS6 SDK 时,我遇到了同样的问题。这是我解决它的方法:

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.

选择发生错误的界面构建器文件(无论是 xib 还是故事板文件)。在 XCode 右侧的辅助编辑器中,选择左侧的第一个选项卡,并有一个“使用自动布局”选项的复选框,如上面的屏幕截图所示。取消选中复选框。

回答by DDRider62

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

Nagaraja问“如果我们不使用xib,如何解决同样的问题?我遇到了这个问题。我用xib创建了一个控制器,然后我决定删除xib文件。崩溃并没有消失。问题是我需要实施

- (void) loadView

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

在我的控制器类中。一旦我实施了这个方法,问题就解决了。

回答by Chris Walken

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.

presentViewController 崩溃的另一个可能原因是笔尖中的某些东西连接到一个不再存在的变量 - 该变量的名称已更改或已被删除。