不知道为什么我的应用程序崩溃了

时间:2015-04-10 16:06:09

标签: ios swift nsunknownkeyexception

我对swift很新,非常新的,我可能会觉得这个问题是个白痴。我非常简单的目标是,当点击我的按钮时,按钮的标题将会消失,但不幸的是,每次运行该应用程序时,应用程序都会崩溃,而我不知道我做错了什么。谢谢你的帮助。

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var background1: UIImageView!
@IBOutlet weak var screenButton: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    self.screenButton.setTitle("Tap!", forState: UIControlState.Normal)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func screenTapped(sender: AnyObject) {
    self.screenButton.setTitle("", forState: UIControlState.Normal)
}

}
2015-04-10 17:13:41.465 TopScore[6391:414281] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key screenTapped.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000104fc0a75 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000106b18bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000104fc06b9 -[NSException raise] + 9
    3   Foundation                          0x00000001053dbd43 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
    4   CoreFoundation                      0x0000000104f0a5e0 -[NSArray makeObjectsPerformSelector:] + 224
    5   UIKit                               0x0000000105b1a4ed -[UINib instantiateWithOwner:options:] + 1506
    6   UIKit                               0x0000000105978a88 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
    7   UIKit                               0x0000000105979078 -[UIViewController loadView] + 109
    8   UIKit                               0x00000001059792e9 -[UIViewController loadViewIfRequired] + 75
    9   UIKit                               0x000000010597977e -[UIViewController view] + 27
    10  UIKit                               0x0000000105898509 -[UIWindow addRootViewControllerViewIfPossible] + 58
    11  UIKit                               0x00000001058988a1 -[UIWindow _setHidden:forced:] + 247
    12  UIKit                               0x00000001058a4f8c -[UIWindow makeKeyAndVisible] + 42
    13  UIKit                               0x000000010584f0c2 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
    14  UIKit                               0x0000000105851e3e -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
    15  UIKit                               0x0000000105850d35 -[UIApplication workspaceDidEndTransaction:] + 179
    16  FrontBoardServices                  0x00000001086ca243 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
    17  CoreFoundation                      0x0000000104ef5c7c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    18  CoreFoundation                      0x0000000104eeb9c5 __CFRunLoopDoBlocks + 341
    19  CoreFoundation                      0x0000000104eeb785 __CFRunLoopRun + 2389
    20  CoreFoundation                      0x0000000104eeabc6 CFRunLoopRunSpecific + 470
    21  UIKit                               0x00000001058507a2 -[UIApplication _run] + 413
    22  UIKit                               0x0000000105853580 UIApplicationMain + 1282
    23  TopScore                            0x0000000104de1cee top_level_code + 78
    24  TopScore                            0x0000000104de1d2a main + 42
    25  libdyld.dylib                       0x00000001072f4145 start + 1
    26  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

1 个答案:

答案 0 :(得分:2)

在某些时候,您不小心设置了名为screenTapped outlet 。您需要在故事板中的Interface Builder中找到该插座并将其删除。

您想要的是从按钮到screenTapped:操作。行动和出路是两件截然不同的事情。