ios - Swift:应用程序因未捕获的异常 'NSUnknownKeyException' 而终止

标签 ios xcode swift runtime-error nsunknownkeyexception

我正在开发一个简单的游戏,在加载特定的 UIViewController(称为 SPSwipes.swift)时遇到问题。 On the screen, there are three buttons: 5, 10, and 25. When one is picked, a variable is set in that scene and the player moves on 到主游戏:GameScene.swift

据我所知变量在 GameScene 中被识别,但是当我打开时出现'NSUnknownKeyException' 错误在模拟器中打开 SPSwipes View 。这是通过 segue 完成的。以下是更详细的错误:

2014-11-09 15:32:43.718 Swipe Racer[2644:1620056] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Swipe_Racer.SPSwipes 0x7fbf52d461b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key fiveSwipes.'
*** First throw call stack:
(
0   CoreFoundation                      0x000000010c021f35 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010dd1bbb7 objc_exception_throw + 45
2   CoreFoundation                      0x000000010c021b79 -[NSException raise] + 9
3   Foundation                          0x000000010c4397b3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4   CoreFoundation                      0x000000010bf6be80 -[NSArray makeObjectsPerformSelector:] + 224
5   UIKit                               0x000000010cd28c7d -[UINib instantiateWithOwner:options:] + 1506
6   UIKit                               0x000000010cb87f98 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7   UIKit                               0x000000010cb88588 -[UIViewController loadView] + 109
8   UIKit                               0x000000010cb887f9 -[UIViewController loadViewIfRequired] + 75
9   UIKit                               0x000000010cb88c8e -[UIViewController view] + 27
10  UIKit                               0x000000010caa7ca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
11  UIKit                               0x000000010caa8041 -[UIWindow _setHidden:forced:] + 247
12  UIKit                               0x000000010cab472c -[UIWindow makeKeyAndVisible] + 42
13  UIKit                               0x000000010ca5f061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
14  UIKit                               0x000000010ca61d2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
15  UIKit                               0x000000010ca60bf2 -[UIApplication workspaceDidEndTransaction:] + 179
16  FrontBoardServices                  0x000000011383b2a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
17  CoreFoundation                      0x000000010bf5753c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18  CoreFoundation                      0x000000010bf4d285 __CFRunLoopDoBlocks + 341
19  CoreFoundation                      0x000000010bf4d045 __CFRunLoopRun + 2389
20  CoreFoundation                      0x000000010bf4c486 CFRunLoopRunSpecific + 470
21  UIKit                               0x000000010ca60669 -[UIApplication _run] + 413
22  UIKit                               0x000000010ca63420 UIApplicationMain + 1282
23  Swipe Racer                         0x000000010be380de top_level_code + 78
24  Swipe Racer                         0x000000010be3811a main + 42
25  libdyld.dylib                       0x000000010e507145 start + 1
26  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

如您所见,我的第一个变量 fiveSwipes 存在问题(我想其他两个变量也会有错误)。 'this class is not key value coding-compliant for the key fiveSwipes 是什么意思?我应该如何修复它?

我的SPSwipes.swift 文件:

class SPSwipes: UIViewController {

var no_of_swipes = 0

@IBAction func fiveSwipes(sender: AnyObject) {
    no_of_swipes = 5

//and so on

}

提前谢谢你,

最佳答案

问题是按钮链接到许多 IBAction - 其中三个不存在。我右键单击Interface Builder 中的按钮并删除了旧的和不相关的链接,解决了问题。

关于ios - Swift:应用程序因未捕获的异常 'NSUnknownKeyException' 而终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26830142/

相关文章:

iOS 11 : Adapt cell size to content with UITableViewAutomaticDimension

ios - 如何使用 XMPPFramework 发送和接收消息

ios - MMDrawerViewController Objective-C 推送到导航 View Controller

ios - 与 Objective-C 应用程序相比,捆绑的 Swift 库的文件大小开销是多少?

swift - 我应该在 swift 中使用 For - in 循环来设置字段值吗

ios - 如何在 Swift 中检查子类中使用了哪个 ViewController

iOS开发应用程序启动崩溃

ios - 如何使用 AVAssetWriter 保存录制的视频?

c++ - xcode 项目中有多个 .cpp 程序?

ios - 当你发出网络请求并且它没有带来图像时如何设置默认图像?