此类不是密钥setDefaultLabelText的密钥值。
我知道那里有类似的问题,我看过他们,但我似乎无法解决问题。我在这个项目上这里实际工作,苹果用来帮助用户学习的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.'
有人帮忙吗?
有没有什么办法可以在我发布的代码中指出我可能在同一个标签或文本字段中有两个插口?从我看到的我看到一个文本字段和一个标签,但我可能会错过一些东西。另外,我在哪里可以看到你放置的黑色视图控制器窗口? –
不,代码似乎没问题,但这是常见的错误。你可能已经做了错误的名字(或者从其他原因来看它是不正确的),然后你从代码中删除它并创建一个新的。问题是,当你从代码中删除插座或动作后,你应该在故事板中断开/删除它。其实,我能够重现类似的错误。这里是截图,你可以清楚地看到如何检查它。 [链接](https://i.imgur.com/EzIEotN.jpg)如果你有黄色警告,你应该使用“X”来断开插座。然后再次与您的代码连接。 –
所以文本字段和标签看起来很好,但我得到了setDefaultLabelText操作的警告:“ViewController没有名为setDefaultLabelText的插座。” –
您的Storyboard中可能存在未使用的插座。 – McNight