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

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

这是什么意思?

我该怎么解决呢?

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


当前回答

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

错误的推控制器方式

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中单独的XIB文件中设计一个小的子视图,并且在IB中将它设置为与父视图相同的类,也会出现这个问题。

如果你像这样显示它:

UIViewController *vc = [[UIViewController alloc] initWithNibName:@"NameOfTheSubviewNibFile" bundle:nil];
[self.view addSubview:vc.view];

视图将出现,但如果它将IBOutlets连接到其File Owner,则会得到错误消息。所以,这应该是有效的:

在父视图的代码中,声明一个IBOutlet UIView *mySubview来引用子视图的nib文件中的视图 在子视图的nib文件中,将file Owner连接到视图,并将其设置为mySubview 你可以这样做:

[[NSBundle mainBundle] loadNibNamed:@"NameOfTheSubviewNibFile" owner:self options:nil]
[self.view addSubview:mySubview];

你会没事的!

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

这个错误是另一回事!

这是我如何解决它。我使用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文件。 在右窗格中,选择文件检查器。 在“Target Membership”部分下,确保选中了适当的构建目标。

希望这能帮助到一些人。

我犯了同样的错误,只是形式略有不同:

在接口构建器中,我有一个自定义子控制器的导航控制器。这个类的名称设置正确,但是NIB名称(选择子控制器,转到属性检查器)被设置为错误的文件(基本上是一个不同的目标)。将其重置为正确的文件名解决了这个问题。