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

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

这是什么意思?

我该怎么解决呢?

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


当前回答

我已经经历过两次了。

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

其他回答

导致这种情况的另一个原因是,您声明该属性实现为@dynamic,但类无法在父类中找到它。

"这个类不符合键值编码" 我知道有点晚了,但我的答案是不同的,所以我认为它需要张贴,我推错了第二个控制器的方式,这里是样本

错误的推控制器方式

UIViewController* controller = [[UIViewController
 alloc]initWithNibName:@"TempViewController" bundle:nil];
         [self.navigationController pushViewController:controller animated:true];

正确的方法

TempViewController* controller = [[TempViewController
 alloc]initWithNibName:@"TempViewController" bundle:nil];
         [self.navigationController pushViewController:controller animated:true];

我没有找到如上的答案,所以它可能可以帮助一些有同样问题的人

我发现的另一个“不兼容”问题是当我出于某种原因设法拥有两个类副本时。

我给错误的副本加了密钥。Interface Builder仍然看到键,并让我连接到它们,但在运行时,它正在使用没有新键的类的另一个副本。

为了找到“正确”的副本,我使用XCode的cmd-点击类名跳转到正确的副本,然后我杀死了不好的未使用的副本(先从未使用的副本中带来我的编辑)。

这个故事的寓意:重复的类文件是不好的。

有时swift文件没有从目标中添加或删除,请转到目标——>构建设置——>编译源——>查看是否缺少任何所需的swift类文件。 在我的情况下,应用程序崩溃,由于swift源文件不存在编译。

这个错误是另一回事!

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

欢呼,