此类与密钥setDefaultLabelText不符合密钥值编码。

时间:2017-10-14 21:06:29

标签: ios swift xcode

我知道那里有类似的问题,我看过它们,但我似乎无法解决问题。我实际上在这个项目上工作,Apple用来帮助用户学习Xcode:https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ConnectTheUIToCode.html#//apple_ref/doc/uid/TP40015214-CH22-SW1

这是我的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.'

有人关心帮忙吗?

1 个答案:

答案 0 :(得分:3)

我认为您有相同标签或文本字段的2个出口。您应该在storyboard中进行检查(右键单击View Controller)。这就是它应该如何看待本教程这一部分的结尾。

Click here

确保没有警告。