1

我刚刚开始快速学习,我无法理解控制台试图通过这个错误告诉我什么。我正在按照 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"
    }
}

预先感谢您的帮助。期待它。

4

1 回答 1

1

已经解决了我的问题。当我刚开始编码时,我尝试将我写的内容复制并粘贴到一个新文件中,现在它可以正常工作了。完全没有问题。这可能是配置的一些错误。不管怎么说,还是要谢谢你。

于 2016-02-23T05:02:40.000 回答