ios - swift NSUnknownKeyException FoodTracker

标签 ios iphone swift nsunknownkeyexception

我刚刚开始学习 swift,我很难理解控制台试图通过这个错误告诉我什么。我正在按照 Apple 的快速学习指南进行操作,在“将 UI 连接到代码”部分中,我遇到了以下问题:

2016-02-22 01:06:54.121 FoodTracker[20300:502503] <CATransformLayer: 0x7fab3973cb90> - changing property contentsCenter in transform-only layer, will have no effect
2016-02-22 01:06:54.127 FoodTracker[20300:502503] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FoodTracker.ViewController 0x7fab394a9a00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key setDefaultLabelText.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001040b7e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000105df7deb objc_exception_throw + 48
    2   CoreFoundation                      0x00000001040b7aa9 -[NSException raise] + 9
    3   Foundation                          0x00000001044809bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
    4   UIKit                               0x0000000104a63320 -[UIViewController setValue:forKey:] + 88
    5   UIKit                               0x0000000104c91f41 -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x0000000103ff84a0 -[NSArray makeObjectsPerformSelector:] + 224
    7   UIKit                               0x0000000104c90924 -[UINib instantiateWithOwner:options:] + 1864
    8   UIKit                               0x0000000104a69eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381
    9   UIKit                               0x0000000104a6a816 -[UIViewController loadView] + 178
    10  UIKit                               0x0000000104a6ab74 -[UIViewController loadViewIfRequired] + 138
    11  UIKit                               0x0000000104a6b2e7 -[UIViewController view] + 27
    12  UIKit                               0x0000000104941ab0 -[UIWindow addRootViewControllerViewIfPossible] + 61
    13  UIKit                               0x0000000104942199 -[UIWindow _setHidden:forced:] + 282
    14  UIKit                               0x0000000104953c2e -[UIWindow makeKeyAndVisible] + 42
    15  UIKit                               0x00000001048cc663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
    16  UIKit                               0x00000001048d2cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
    17  UIKit                               0x00000001048cfe7b -[UIApplication workspaceDidEndTransaction:] + 188
    18  FrontBoardServices                  0x0000000107c8c754 -[FBSSerialQueue _performNext] + 192
    19  FrontBoardServices                  0x0000000107c8cac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    20  CoreFoundation                      0x0000000103fe3a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    21  CoreFoundation                      0x0000000103fd995c __CFRunLoopDoSources0 + 556
    22  CoreFoundation                      0x0000000103fd8e13 __CFRunLoopRun + 867
    23  CoreFoundation                      0x0000000103fd8828 CFRunLoopRunSpecific + 488
    24  UIKit                               0x00000001048cf7cd -[UIApplication _run] + 402
    25  UIKit                               0x00000001048d4610 UIApplicationMain + 171
    26  FoodTracker                         0x0000000103ed947d main + 109
    27  libdyld.dylib                       0x000000010690092d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

此外,这是我正在运行的代码:

import UIKit

class ViewController: UIViewController {

    //MARK: Propierties
    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var mealNameLabel: UILabel!


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

    //MARK: Actions

    @IBAction func setDefaultLabelText(sender: UIButton) {
        mealNameLabel.text = "Default Text"
    }
}

预先感谢您的帮助。敬请期待。

最佳答案

已经解决了我的问题。当我刚开始编写代码时,我尝试将我编写的内容复制并粘贴到一个新文件中,现在它工作得很好。完全没有问题。这可能是配置的一些错误。无论如何谢谢。

关于ios - swift NSUnknownKeyException FoodTracker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35545731/

相关文章:

iphone - 如何在 applicationDidBecomeActive 的 UIButton 中重新加载图像

json - 使用 Swift 4 的 Codable 进行类型转换

ios - 如何创建UITextField以在编辑被键盘覆盖的UITextField时显示文本

iOS - swift 3 - DispatchGroup

ios - 不兼容的整数到指针的转换将 'NSInteger'(又名 'int')发送到类型为 'NSInteger *'(又名 'int *')的参数

ios - 如何在 iOS 6.1 中将字符串转换为 base64 编码

ios - 如何查看 Game Center 设备的 iOS 版本?

arrays - 如何附加到作为 Swift 字典中值的数组

ios - 使用Auto Layout的iAd ADBannerView有多种外观

ios - 如何软化 TableView 中的 begin 和 endUpdates