我正在製作一個小型的iOS應用程序,用於跟蹤我工作時鐘的時間。我對Swift和Xcode很陌生,所以這對我來說是一個挑戰。詳情:我正在使用Xcode 7,目標開發是8.3。我相信我缺少像類文件這樣的小東西。 該應用程序在啓動時崩潰。爲什麼我在setValue中獲取NSUnknownKeyException:forUndefinedKey:?
錯誤:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ButtonIn.'
代碼:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBOutlet weak var Lb1: UILabel!
@IBAction func ButtonIn(sender: AnyObject) {
self.Lb1.text = "Clocked In!"
}
@IBAction func ButtonOut(sender: AnyObject) {
self.Lb1.text = "Clocked Out!"
}
}
檢查與此視圖控制器關聯的xib。在xCode中搜索「ButtonIn」。你應該在那裏找到它。 – ajmccall
是的,看起來你在故事板中有一些設置錯誤。你可以張貼你如何連接網點和操作的截圖嗎? –
此外,這是一個質量很低的問題。標題是多餘的。請查看SO指導原則,否則您將無法獲得答案,您的問題將被拒絕投票。 http://stackoverflow.com/help/how-to-ask – ajmccall