2017-10-14 39 views
1

我知道那裏有類似的問題,我看過他們,但我似乎無法解決問題。我在這個項目上這裏實際工作,蘋果用來幫助用戶學習的Xcode:https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ConnectTheUIToCode.html#//apple_ref/doc/uid/TP40015214-CH22-SW1此類不是密鑰setDefaultLabelText的密鑰值。

這是我的ViewController.swift代碼:

import UIKit 

class ViewController: UIViewController { 
    //MARK: Properties 
    @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" 
    } 
} 

我保持甚至收到此錯誤時,我遵循所有的步驟:

2017-10-14 16:18:49.195098-0400 FoodTracker[1946:46609] [MC] Lazy loading 
NSBundle MobileCoreServices.framework 
2017-10-14 16:18:49.195968-0400 FoodTracker[1946:46609] [MC] Loaded 
MobileCoreServices.framework 
2017-10-14 16:18:49.211086-0400 FoodTracker[1946:46609] [MC] System group 
container for systemgroup.com.apple.configurationprofiles path is 
/Users/xcodeclub/Library/Developer/CoreSimulator/Devices/54569EE9-2F14-41C6- 
94D7-EDB605459B46/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 
2017-10-14 16:18:49.221000-0400 FoodTracker[1946:46609] *** Terminating app 
due to uncaught exception 'NSUnknownKeyException', reason: 
'[<FoodTracker.ViewController 0x7fc93bf08b80> setValue:forUndefinedKey:]: 
this class is not key value coding-compliant for the key setDefaultLabelText.' 

有人幫忙嗎?

+0

您的Storyboard中可能存在未使用的插座。 – McNight

回答

2

我認爲你有2個網點用於相同的標籤或文本框。您應該在故事板中檢查它(右鍵單擊View Controller)。這就是它應該看這部分教程的最後部分。

Click here

確保沒有任何警告。

+0

有沒有什麼辦法可以在我發佈的代碼中指出我可能在同一個標​​籤或文本字段中有兩個插口?從我看到的我看到一個文本字段和一個標籤,但我可能會錯過一些東西。另外,我在哪裏可以看到你放置的黑色視圖控制器窗口? –

+0

不,代碼似乎沒問題,但這是常見的錯誤。你可能已經做了錯誤的名字(或者從其他原因來看它是不正確的),然後你從代碼中刪除它並創建一個新的。問題是,當你從代碼中刪除插座或動作後,你應該在故事板中斷開/刪除它。其實,我能夠重現類似的錯誤。這裏是截圖,你可以清楚地看到如何檢查它。 [鏈接](https://i.imgur.com/EzIEotN.jpg)如果你有黃色警告,你應該使用「X」來斷開插座。然後再次與您的代碼連接。 –

+0

所以文本字段和標籤看起來很好,但我得到了setDefaultLabelText操作的警告:「ViewController沒有名爲setDefaultLabelText的插座。」 –

相關問題