我试图将UILabel与在类中创建的IBOutlet链接起来。

我的应用程序崩溃与以下错误。

这是什么意思?

我该怎么解决呢?

***终止应用由于未捕获异常'NSUnknownKeyException',原因:'[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]:这个类不是键值编码兼容的键XXX。'


当前回答

NSUnknownKeyException error

'NSUnknownKeyException', reason: this class is not key value coding-compliant for the key

我得到这个错误时。xib文件(例如。TableViewCell.xib)具有与单元格类相同的名称(例如。TableViewCell.swift)

正确的做法是:

TableViewCell.swift -> View.swift <-> View.xib

其他回答

我有这个发生时,我有一个UIView链接到一个故事板和连接IBOutlet像:

@property (strong, nonatomic) IBOutlet UIView *someView

但是后来,我把UIView做成了一个自定义类,但是忘记改变上面定义的IBOutlet的类名。这是一个奇怪的错误,因为如果自定义视图没有子视图,它不会抱怨,但只要有子视图,它就会显示问题中陈述的错误,但在其中一个子视图上,而不是在问题实际存在的外部UIView上。让我删除和读取所有的子视图试图找到问题,而实际上与子视图无关

就我而言,

[[NSBundle mainBundle] loadNibNamed:@"NameOfTheSubviewNibFile" owner:self options:nil]

这就是原因。

将此替换为initWithNibName,已解决。

如果它只是一个iPhone应用,而不是一个通用的应用,请确保以下字段为空:

目标>摘要> iPhone/iPod部署信息>主界面

如果你在这里指定了xib,它会崩溃。

这个错误是另一回事!

这是我如何解决它。我使用xcode版本6.1.1和使用swift。每次我的应用程序尝试执行segue跳转到下一个屏幕时,我都得到这个错误。这是我所做的。

Checked that the button was connected to the right action.(This wasn't the problem, but still good to check) Check that the button does not have any additional actions or outlets that you may have created by mistake. (This wasn't the problem, but still good to check) Check the logs and make sure that all the buttons in the NEXT SCREEN have the correct actions, and if there are any segues, make sure that they have a unique identifier. (This was the problem) One of the segues did not have a unique identifier One of the buttons had an action and two outlets that I created by mistake. Delete any additional outlets and make sure that you the segues to the next screen have unique identifiers.

欢呼,

我在为表视图原型单元创建的自定义类的所有出口上都遇到了这个错误。出口都正确地连接到故事板,并且Class字段在原型单元格的标识检查器中被正确地命名。

删除和重新创建出口都不起作用。清理构建没有起作用。最后有效的方法是将故事板标识检查器中的Class更改为默认的UITableViewCell,点击Enter,然后将其更改为自定义类的名称。出于某种原因,这奏效了。