2016-02-22 70 views
1

我剛剛開始學習swift,並且我無法理解控制檯試圖告訴我這個錯誤。我按照蘋果的指導,學習迅速,並在部分「用戶界面連接到代碼」我有以下問題:Swift NSUnknownKeyException FoodTracker

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" 
    } 
} 

非常感謝您的幫助。期待它。

回答

0

已經解決了我的問題。當我剛剛開始編寫代碼時,我嘗試將我寫入的內容複製並粘貼到一個新文件中,現在它完美地工作。沒有問題。這可能是一些配置錯誤。不管怎麼說,還是要謝謝你。

相關問題