xcode 此类不符合键值编码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19532373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:09:38  来源:igfitidea点击:

This class is not key value coding-compliant

iosobjective-cxcodeiboutlet

提问by Jojodmo

When I try to run my application on the iPhone simulator, It crashes and I get this error:

当我尝试在 iPhone 模拟器上运行我的应用程序时,它崩溃并收到此错误:

2013-10-22 20:24:02.367 brainademy[46328:a0b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0xcc6de90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ChooseGameViewController.'
*** First throw call stack:
(
0   CoreFoundation                      0x01a0d5e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x017908b6 objc_exception_throw + 44
2   CoreFoundation                      0x01a9d6a1 -[NSException raise] + 17
3   Foundation                          0x01451c2e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4   Foundation                          0x013bdf3b _NSSetUsingKeyValueSetter + 88
5   Foundation                          0x013bd493 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6   Foundation                          0x0141f94a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
7   UIKit                               0x007a4cd5 -[UIRuntimeOutletConnection connect] + 106
8   libobjc.A.dylib                     0x017a27d2 -[NSObject performSelector:] + 62
9   CoreFoundation                      0x01a08b6a -[NSArray makeObjectsPerformSelector:] + 314
10  UIKit                               0x007a382e -[UINib instantiateWithOwner:options:] + 1417
11  UIKit                               0x007a55bb -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 165
12  UIKit                               0x00502fcb -[UIApplication _loadMainNibFileNamed:bundle:] + 58
13  UIKit                               0x005032f9 -[UIApplication _loadMainInterfaceFile] + 245
14  UIKit                               0x00501e9f -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 543
15  UIKit                               0x0051642c -[UIApplication handleEvent:withNewEvent:] + 3447
16  UIKit                               0x00516999 -[UIApplication sendEvent:] + 85
17  UIKit                               0x00503c35 _UIApplicationHandleEvent + 736
18  GraphicsServices                    0x0319e2eb _PurpleEventCallback + 776
19  GraphicsServices                    0x0319ddf6 PurpleEventCallback + 46
20  CoreFoundation                      0x01988dd5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
21  CoreFoundation                      0x01988b0b __CFRunLoopDoSource1 + 523
22  CoreFoundation                      0x019b37ec __CFRunLoopRun + 2156
23  CoreFoundation                      0x019b2b33 CFRunLoopRunSpecific + 467
24  CoreFoundation                      0x019b294b CFRunLoopRunInMode + 123
25  UIKit                               0x005016ed -[UIApplication _run] + 840
26  UIKit                               0x0050394b UIApplicationMain + 1225
27  brainademy                          0x0000b01d main + 141
28  libdyld.dylib                       0x02e8c725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Most of the time, this is going to mean that I have something in my File's owner, an IBOutlet or IBAction that is not declared, yet this is not the case. I have looked at every single other question like this and none of them have helped.

大多数情况下,这意味着我的文件所有者中有一些东西,即未声明的 IBOutlet 或 IBAction,但事实并非如此。我已经看过像这样的每个其他问题,但没有一个有帮助。

ChooseGameViewController ISdeclared, so that shouldn't cause any problems, but I tried unhooking it from the File's owner, and when I do, and run my app, It crashes and instead of ChooseGameViewController it's ColorGameViewController. I tried removing every single one of my ViewController IBOutlets, and when I did that, I got other IBOutlets, like labels and buttons, that showed up in the error instead of ChooseGameViewController. I get no errors next to any of my outlets, like you usually would if you had an non-declared outlet.

ChooseGameViewController IS宣称,这样不会引起任何问题,但我想从文件的所有者脱钩它,当我这样做,并运行我的应用程序,它崩溃,而不是ChooseGameViewController它的ColorGameViewController。我尝试删除我的 ViewController IBOutlets 中的每一个,当我这样做时,我得到了其他 IBOutlets,比如标签和按钮,它们出现在错误中而不是 ChooseGameViewController。我的任何出口旁边都没有错误,就像您拥有未声明的出口一样。

I tried making a clean build, but that didn't work, and my File's owner is hooked up to the correct class (RootViewController)

我尝试进行干净的构建,但这不起作用,并且我的文件所有者已连接到正确的类(RootViewController)

This app was working fine just a while ago, and I just opened up Xcode today and I started getting these errors.

不久前这个应用程序运行良好,我今天刚刚打开 Xcode,我开始收到这些错误。

This is not a problem with non-declared outlets, because:

这对于未申报的网点来说不是问题,因为:

  • All the outlets AREdeclared
  • I get no errors in the file's owner
  • This error happens with every single IBOutlet, and IBOutlets only
  • 所有网点ARE声明
  • 我在文件所有者中没有发现错误
  • 每个IBOutlet都会发生此错误,并且仅 IBOutlets

What is the cause of this error?

这个错误的原因是什么?

采纳答案by Jojodmo

I fixed it by creating a new Xcode project and copying everything over, which makes me think it had something to do with the me trying to add support for iPad.

我通过创建一个新的 Xcode 项目并复制所有内容来修复它,这让我认为这与我尝试添加对 iPad 的支持有关。

This happens whenever I try to do this, even making a new application, making it universal, and making the new .xibfile for iPad, and hooking it up via the project manager.

每当我尝试这样做时都会发生这种情况,甚至制作一个新应用程序,使其通用,并.xib为 iPad制作新文件,并通过项目经理将其连接起来。

Even when I remove support for iPad the error above still shows, I think I have to do something with just changing the view controller using code.

即使我取消了对 iPad 的支持,上面的错误仍然显示,我想我必须做一些事情,只需使用代码更改视图控制器。

回答by Bryan Chen

It shouldn't look ChooseGameViewControlleron UIApplication.

它不应该看ChooseGameViewControllerUIApplication

I guess your AppDelegatehave a property ChooseGameViewControllerso you need to go to interface builder and make sure your outlets hook to AppDelegatenot UIApplication

我猜你AppDelegate有一个属性,ChooseGameViewController所以你需要去界面构建器并确保你的插座钩AppDelegateUIApplication

If you have source control, make a diff and see what's changed. Otherwise you can open .xibfile using XML editor and check it does not contain UIApplicationin unexpected place.

如果你有源代码控制,做一个差异,看看有什么变化。否则,您可以.xib使用 XML 编辑器打开文件并检查它是否包含UIApplication在意外的地方。

回答by Sid

I got the same issue when I deleted one IBOutlet property from a class. I see storyboard still keep the IBOutlet link even when deleting the IBOutlet property.

当我从类中删除一个 IBOutlet 属性时,我遇到了同样的问题。我看到即使删除 IBOutlet 属性,情节提要仍然保留 IBOutlet 链接。

Solution

解决方案

  1. Find in your class if you deleted any Outlet property
  2. Navigate to the storyboard find the object and Outlet link and remove
  1. 如果您删除了任何 Outlet 属性,请在您的班级中查找
  2. 导航到情节提要找到对象和插座链接并删除

Hope this work for you.

希望这对你有用。