我有这样的错误。
This class is not key value coding-compliant for the key ptbLabel.
我知道当故事板和源代码之间的链接出现问题时会发生此错误。
所以,我从故事板中删除了链接。
然后这个错误就消失了。
但我手动重新连接故事板。
@IBOutlet weak var ptbLabel: UIImageView!
它显示相同的错误。
为什么会这样?
我想这可能与项目名称更改有关。
我之前几步更改了项目名称,方法是点击左侧疼痛顶部的项目名称。
这些是下面的错误日志
] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7ff6e0404580> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ptbLabel.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000110901b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001102c5141 objc_exception_throw + 48
2 CoreFoundation 0x0000000110901a59 -[NSException raise] + 9
3 Foundation 0x000000010f6f1e8b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x000000010dfe0644 -[UIViewController setValue:forKey:] + 87
5 UIKit 0x000000010e24d6b9 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001108a7e8d -[NSArray makeObjectsPerformSelector:] + 269
7 UIKit 0x000000010e24c06f -[UINib instantiateWithOwner:options:] + 1856
8 UIKit 0x000000010dfe6c73 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x000000010dfe7589 -[UIViewController loadView] + 177
10 UIKit 0x000000010dfe78ba -[UIViewController loadViewIfRequired] + 195
11 UIKit 0x000000010dfe810a -[UIViewController view] + 27
12 UIKit 0x000000010deb063a -[UIWindow addRootViewControllerViewIfPossible] + 65
13 UIKit 0x000000010deb0d20 -[UIWindow _setHidden:forced:] + 294
14 UIKit 0x000000010dec3b6e -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x000000010de3d31f -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4346
16 UIKit 0x000000010de43584 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1709
17 UIKit 0x000000010de40793 -[UIApplication workspaceDidEndTransaction:] + 182
18 FrontBoardServices 0x00000001149875f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
19 FrontBoardServices 0x000000011498746d -[FBSSerialQueue _performNext] + 186
20 FrontBoardServices 0x00000001149877f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x00000001108a7c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x000000011088d0cf __CFRunLoopDoSources0 + 527
23 CoreFoundation 0x000000011088c5ff __CFRunLoopRun + 911
24 CoreFoundation 0x000000011088c016 CFRunLoopRunSpecific + 406
25 UIKit 0x000000010de3f02f -[UIApplication _run] + 468
26 UIKit 0x000000010de450d4 UIApplicationMain + 159
27 BeatBrain 0x000000010be5dcb0 main + 48
28 libdyld.dylib 0x000000011198d65d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
--------解决方案-------
我打开了故事板作为源代码。
然后发现我更改项目名时没有更改customModule。
<viewController id="2" customClass="viewController" customModule="OldProjectName" sceneMemberID="viewController">
我在这里更改了OldProjectName - &gt; NewProjectName
它有效。
非常感谢。