一两天前开始学习 Swift。我遇到这个错误的次数比我想的要多——本质上,我意识到它与 IBOutlets 有关。删除情节提要中的所有插座和按钮/对象,然后手动重新添加它们似乎可以解决问题。
将来如果发生此错误,并且我正在从事一个大型项目,我想知道如何诊断它是哪个 IBOutlet,或者可能是什么原因导致了这种情况。
如果有人想看一下并留下几句建议,我在 GitHub 上有一个项目的副本。
提前致谢!
2015-06-04 22:24:31.607 Controlling The Keyboard[1343:16382] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Controlling_The_Keyboard.ViewController 0x7f80896418b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key enterButton.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000104855c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001063c0bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001048558a9 -[NSException raise] + 9
3 Foundation 0x0000000104c73b53 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x000000010479dd50 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x00000001053cc52b -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x0000000105224718 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x0000000105224d08 -[UIViewController loadView] + 109
8 UIKit 0x0000000105224f79 -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x000000010522540e -[UIViewController view] + 27
10 UIKit 0x00000001051402c9 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x000000010514068f -[UIWindow _setHidden:forced:] + 247
12 UIKit 0x000000010514ce21 -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x00000001050f0457 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
14 UIKit 0x00000001050f31de -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
15 UIKit 0x00000001050f20d5 -[UIApplication workspaceDidEndTransaction:] + 179
16 FrontBoardServices 0x0000000107ed05e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21
17 CoreFoundation 0x000000010478941c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x000000010477f165 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x000000010477ef25 __CFRunLoopRun + 2389
20 CoreFoundation 0x000000010477e366 CFRunLoopRunSpecific + 470
21 UIKit 0x00000001050f1b42 -[UIApplication _run] + 413
22 UIKit 0x00000001050f4900 UIApplicationMain + 1282
23 Controlling The Keyboard 0x0000000104654f37 main + 135
24 libdyld.dylib 0x0000000106b18145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)