为什么我收到一个名为NSUnknownKeyException的错误?

时间:2017-11-25 00:14:43

标签: ios swift xcode

好吧,所以我正在关注Swift 2的教程,即使我正在运行Swift 4,我也不认为这很重要,因为教程说的所有内容都适用于我的代码。 然而,我遇到了添加分数的问题。代码就像

@IBAction func RedBtnAction(_ sender: Any) {
    Score ++
    RedBtnLbl.text = "\(Score)"
    BluBtnLbl.text = "\(Score)"
}

但是我看到了,在Xcode 9或Swift 4中仍然没有使用它。我搜索了它并且实际上在这里找到了答案!它说(分数++)改为(分数+ = 1)所以我做了但是它然后给了我NSUnknownKeyException。我的整个代码现在就像这样,它仍然给我错误,所以有人可以帮忙吗?

导入UIKit

类ViewController:UIViewController {

@IBOutlet weak var TopBtn: UIButton!
@IBOutlet weak var BtmBtn: UIButton!

@IBOutlet weak var RedBtnLbl: UILabel!
@IBOutlet weak var BluBtnLbl: UILabel!

var Score = 0

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    Score = 0

    RedBtnLbl.text = "\(Score)"
    BluBtnLbl.text = "\(Score)"

    RedBtnLbl.transform = CGAffineTransform(rotationAngle: 3.14)


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


@IBAction func RedBtnAction(_ sender: Any) {
    Score += 1
    RedBtnLbl.text = "\(Score)"
    BluBtnLbl.text = "\(Score)"
}
@IBAction func BluBtnAct(_ sender: Any) {
    Score -= 1
    RedBtnLbl.text = "\(Score)"
    BluBtnLbl.text = "\(Score)"
}
}

再次感谢! 链接到教程:https://www.youtube.com/watch?v=mNFXvceJ0wc&t=412s

0 个答案:

没有答案