gpt4 book ai didi

ios - 未捕获的异常 : This class is not key value coding-compliant

转载 作者:行者123 更新时间:2023-11-30 14:01:16 26 4
gpt4 key购买 nike

我正在关注a tutorial titled "Swift Tutorial for iOS : NSFileManager Persisting Data" ,并且我在 29 分钟左右或之后遇到了错误。当我尝试在 iOS 模拟器上运行它时,收到错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key theLoadMethod.'

显然基于错误,我认为问题是我的 theLoadMethod 。这是我在 ViewController 中作为该项目的一部分编写的全部代码:

let theDocumentsFolder = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let theFileName = "/theUserFile.txt"
let thePath = theDocumentsFolder.stringByAppendingString(theFileName)


class ViewController: UIViewController {

@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var lastNameTextField: UITextField!
@IBOutlet weak var ageTextField: UITextField!

@IBOutlet weak var theLabel: UILabel!

// The save method
@IBAction func theSaveMethod(sender: AnyObject) {
var name = nameTextField.text
var lastName = lastNameTextField.text
var age = ageTextField.text

var theString = "The user's information is: \(name), \(lastName), \(age)"

let theFileManager = NSFileManager.defaultManager()

if !theFileManager.fileExistsAtPath(thePath) {

var writeError:NSError?
let fileToBeWritten = theString.writeToFile(thePath, atomically: true, encoding: NSUTF8StringEncoding, error: &writeError)

if writeError == nil {
println("No errors. Added: \(theString)")
} else {
println("Encountered an error. Error is: \(writeError)")
}

} else {
println("File already exists")
}

nameTextField.resignFirstResponder()
lastNameTextField.resignFirstResponder()
ageTextField.resignFirstResponder()
}

@IBAction func theLoadMethod(sender: AnyObject) {
let infoFromFile:String = String.stringWithContentsOfFile(thePath, encoding: NSUTF8StringEncoding, error: nil)!

theLabel.text = infoFromFile
}

我是不是做错了什么?据我所知,我的所有 iOS 屏幕元素都已正确命名和链接。

最佳答案

这通常是由 Storyboard到不存在的属性的链接引起的。仔细检查 Storyboard中对象的所有链接。此外,如果您更改了属性或方法的名称或拼写,它仍然可以引用旧的。

关于ios - 未捕获的异常 : This class is not key value coding-compliant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32959804/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com