我试图将UILabel与在类中创建的IBOutlet链接起来。
我的应用程序崩溃与以下错误。
这是什么意思?
我该怎么解决呢?
***终止应用由于未捕获异常'NSUnknownKeyException',原因:'[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]:这个类不是键值编码兼容的键XXX。'
我试图将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.
欢呼,
其他回答
我因为不同的原因遇到了同样的问题:我使用主故事板作为启动屏幕文件。我猜如果你使用一个故事板作为启动屏幕文件,它不应该连接到视图控制器,因为它还没有被加载。
您只需要指定IBOutlet一次,IBOutlet标签您的ivar是不必要的。 你在用你的UIViewController实例化你的NIB吗?在某些时候,你应该调用[SecondView initWithNibName:@"yourNibName" bundle:nil];
如果您想在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];
你会没事的!
我也有同样的问题。我重置了模拟器。删除和添加按钮控件。终于搞干净了。:)由于堆栈溢出。不知怎么的,我的代码变得很好,开始工作。
通过在Storyboard/xib接口中选择有问题的对象并打开连接检查器(视图->Utilities->显示连接检查器)来检查是否有丢失的引用出口。如果您确实删除了不需要的连接,您应该可以继续。