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

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

这是什么意思?

我该怎么解决呢?

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


当前回答

这个错误是另一回事!

这是我如何解决它。我使用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.

欢呼,

其他回答

我已经经历过两次了。

解决方案是重新制作整个故事板,因为我从另一个故事板复制了它(因为它几乎是相同的)

确保你在.m文件中添加了自定义类的实现(甚至是空的),如下所示:

@implementation MySubclass
@end

我在故事板中得到这个错误。上面的解决方案似乎不是问题,所以我最终删除了视图控制器,并再次将它添加回来(当然,重新连接segue并重新分配类),这就修复了它。我不知道它到底是什么,但我在这个开始前不久重命名了关联的视图控制器类,所以可能有一些东西。

在我的例子中,这是因为引用了错误的Nib:

BMTester *viewController = [[BMTester alloc] initWithNibName:@"WrongNibName" bundle:nil];

当一个UI标签或其他UI元素被视图控制器类中的两个变量引用,而我删除了其中一个变量时,我也会遇到这种情况。