无法实例化名为IBNSLayoutConstraint的类 [英] Could not instantiate class named IBNSLayoutConstraint

查看:197
本文介绍了无法实例化名为IBNSLayoutConstraint的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XCode6 beta并试用Swift。当我在视图控制器中放置一些自动布局约束时,应用程序崩溃并出现以下错误:
由于未捕获的异常'NSInvalidUnarchiveOperationException'而终止应用程序,原因:'无法实例化名为IBNSLayoutConstraint的类' / code>

I'm using XCode6 beta and trying out Swift. When I put some auto layout constraints in a view controller the app crashes with the following error: Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named IBNSLayoutConstraint'

推荐答案

您收到此错误是因为您已将约束设置为已删除的IBOutlet在运行时。在Interface Builder中将约束设置为占位符时会发生这种情况。由于约束被删除,当它去掉它时,它会抛出一个错误,说它不能这样做。

You're getting this error because you've set a constraint to an IBOutlet that is removed at runtime. This happens when you set the constraint to be a placeholder in Interface Builder. Since the constraint is removed, when it goes to unarchive it, it throws an error saying it can't do so.

有两种方法可以解决这个问题。

There are two ways to correct this.


  1. 右键单击故事板>打开方式>源代码

  2. 在打开的故事板xml中,搜索占位符=是

  3. 你'找到设置为在运行时删除的约束。从约束中删除占位符属性,保存并关闭。

  4. 运行应用程序并解决您的问题。

  1. Right-click on your Storyboard > Open As > Source Code
  2. In the opened storyboard xml, search for placeholder="YES".
  3. You'll find constraints that are set to be removed at runtime. Remove the placeholder attribute from the constraint, save and close.
  4. Run the app and your problem should be fixed.



方法2



Method 2


  1. 在Interface Builder中找到导致问题的约束。取消选中GUI中的占位符选项。这应该是在ViewController中设置为导致崩溃的IBOutlet的约束之一。

这是它应该看起来的样子喜欢:

This is what it should look like:

假设您确实希望约束为占位符,那么您需要删除任何引用插座。为此,请选择您希望成为占位符的约束。然后打开连接检查器(最右边的按钮,如下所示:( - >)),然后删除该约束上可能存在的任何引用插座。

Assuming you actually want the constraint to be a placeholder, then you'll need to remove any referencing outlets. To do this, select the constraint that you wish to be a placeholder. Then open the connections inspector (the button furthest to the right that looks like this: (->) ) and then remove any referencing outlets that may exist on that constraint.

这篇关于无法实例化名为IBNSLayoutConstraint的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆