对于键<key>,此类不符合键值编码,其中<key>不在代码中(swift,Xcode 6)

Eri*_*c R 1 xcode runtime-error ios swift

我已经输入了一个程序,其代码如下所示,来自一个教程,试图在几年后重新编写代码.

当我运行代码时,所有内容都会构建,但随后它会因上面的主题行错误而崩溃,并命名一个在我的代码中没有出现的键("helloText").下面的完整错误输出.

扭曲:有一次,我将其中一个出口命名为"helloText"(现在命名为"nameTextField").

我查看了与我能找到的项目相关的每个文件,但找不到"helloText".我还尝试了菜单项"干净".

谢谢你的指导.

//
//  ViewController.swift
//  ConstructOStraws
//
//  Created by Eric on 11/12/14.
//  Copyright (c) 2014 Eric. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

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

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


    @IBOutlet weak var helloLabel: UILabel!
    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var helloButton: UIButton!

    func setupUI(){

        helloLabel.text = "Hello Swift!"
        helloLabel.textColor = UIColor.redColor()
        helloLabel.textAlignment = NSTextAlignment.Center

        nameTextField.placeholder = "Enter your name"

    helloButton.setTitle("Say Hell", forState: .Normal)

    }


    @IBAction func sayHelloAction(sender: AnyObject) {

        let name = nameTextField.text

        if name.isEmpty {

            let alert = UIAlertController(title: "Error", message: "Please Enter a Name.", preferredStyle: UIAlertControllerStyle.Alert)

            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))

            self.presentViewController(alert, animated: true, completion: nil)
        } else {

            helloLabel.text = "Hello \(name)"
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

错误:

2014-11-12 15:23:10.521 ConstructOStraws[2048:67817] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ConstructOStraws.ViewController 0x7f82e866b420> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key helloText.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001043b7f35 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000105efbbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x00000001043b7b79 -[NSException raise] + 9
    3   Foundation                          0x00000001047cf7b3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
    4   CoreFoundation                      0x0000000104301e80 -[NSArray makeObjectsPerformSelector:] + 224
    5   UIKit                               0x0000000104f08c7d -[UINib instantiateWithOwner:options:] + 1506
    6   UIKit                               0x0000000104d67f98 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
    7   UIKit                               0x0000000104d68588 -[UIViewController loadView] + 109
    8   UIKit                               0x0000000104d687f9 -[UIViewController loadViewIfRequired] + 75
    9   UIKit                               0x0000000104d68c8e -[UIViewController view] + 27
    10  UIKit                               0x0000000104c87ca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
    11  UIKit                               0x0000000104c88041 -[UIWindow _setHidden:forced:] + 247
    12  UIKit                               0x0000000104c9472c -[UIWindow makeKeyAndVisible] + 42
    13  UIKit                               0x0000000104c3f061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
    14  UIKit                               0x0000000104c41d2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
    15  UIKit                               0x0000000104c40bf2 -[UIApplication workspaceDidEndTransaction:] + 179
    16  FrontBoardServices                  0x0000000107a9b2a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
    17  CoreFoundation                      0x00000001042ed53c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    18  CoreFoundation                      0x00000001042e3285 __CFRunLoopDoBlocks + 341
    19  CoreFoundation                      0x00000001042e3045 __CFRunLoopRun + 2389
    20  CoreFoundation                      0x00000001042e2486 CFRunLoopRunSpecific + 470
    21  UIKit                               0x0000000104c40669 -[UIApplication _run] + 413
    22  UIKit                               0x0000000104c43420 UIApplicationMain + 1282
    23  ConstructOStraws                    0x00000001041d661e top_level_code + 78
    24  ConstructOStraws                    0x00000001041d665a main + 42
    25  libdyld.dylib                       0x00000001066d5145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
Run Code Online (Sandbox Code Playgroud)

ldi*_*ndu 7

如果您已重命名IBOutlets,那么您可能不会删除故事板中旧引用的引用,这些引用可能如下所示

附上截图

使用黄色感叹号三角形删除出口参考,如屏幕所示.您可以在视图控制器的故事板中右键单击First Responder旁边的视图控制器对象,进入此屏幕.