ios - 打开 xib 文件时显示错误

标签 ios uiviewcontroller uinavigationcontroller xib

当我点击表格 View 行时,我使用以下代码打开xib

ViewController *List=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
      [self.navigationController pushViewController:List animated:YES];

我得到了这个异常

    Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint'
*** First throw call stack:
(0x245e052 0x1731d0a 0x2406a78 0x24069e9 0xbbe7d7 0xbbe9af 0xbbe6b7 0xabf36d 0x966e2c 0x9673a9 0x9675cb 0x967941 0x97947d 0x97966f 0x97993b 0x97a3df 0x97a986 0x97a5a4 0x41b08 0x93171d 0x931952 0x11b986d 0x2432966 0x2432407 0x23957c0 0x2394db4 0x2394ccb 0x391a879 0x391a93e 0x8a1a9b 0x28dd 0x2805)
terminate called throwing an exception(lldb) 

最佳答案

发生这种情况是因为您使用的是 Xcode 4.5+(或之前的测试版),它默认使用“自动布局”。自动布局仅在 iOS 6 上可用,因此您将在以前的 iOS 版本上收到运行时错误。

您可以通过打开 Storyboard、打开实用程序 Pane 并禁用第一个选项卡/部分中的“使用自动布局”复选框来解决此问题:

enter image description here

对于常规 Non-Storyboard Nib ,选择顶级 View 以访问此选项。

关于ios - 打开 xib 文件时显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16482610/

相关文章:

ios - viewDidDisappear 永远不会在自定义选项卡中被调用

ios - 每个 ViewController 创建只调用一次的回调

ios - 在按钮操作上实例化 UINavigationController

ios - 更改包标识符会导致应用程序在模拟器中失败

ios - 线程(异步队列)在 Swift 中是如何工作的?

ios - shouldAutorotateToInterfaceOrientation 没有被调用

iphone - 如何更改 iOS 中 Navigation Controller 的工具栏颜色?

ios导航 Controller 推送 View Controller 但有后退按钮指向其他地方

ios - 为什么 AUNetSend 在 iOS 上不可用? (或任何替代建议)

ios - RMStore离线收货验证