1

だから私はチュートリアルを進めており、著者の手紙に従っていることを確認しました。私のコードは次のエラーをスローします。

2014-10-01 22:26:14.545 stopwatch2[3503:861733] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<stopwatch2.ViewController 0x7c57f050> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key pause.'

私の質問は:

提供されたエラーに基づいて、アプリケーションが失敗する理由は何ですか?

コンパイルされない私のコードは次のとおりです。

import UIKit

class ViewController: UIViewController {

    var timer = NSTimer()

    @IBOutlet var time : UILabel!
    var count = 0

    @IBAction func play(sender : AnyObject) {

    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("result"), userInfo: nil, repeats: true)
    }

    @IBAction func pause(sender : AnyObject) {
        timer.invalidate()
    }


    @IBAction func reset(sender : AnyObject) {
        timer.invalidate()
        count = 0
        time.text="0"
    }



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



    }

    func result() {
        count++
        time.text = String(count)
    }

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


}

私が本当に知りたいのは、著者が他のビデオでも同じ結果をもたらすと確信しているため、これを自分で調査する方法です.

ビデオは、udemy.com、The Complete iOS8 および Swift Course からのものです。

助けてくれてありがとう。

4

1 に答える 1

5

「このクラスは、キーポーズのキー値コーディングに準拠していません」は、通常、参照アウトレットの問題があることを意味します。接続インスペクターで、さまざまなボタンを探します。次のいずれかを持っている可能性があります。

1 つのボタンに対して 2 つの参照アウトレットがあり、プログラムはどちらを使用するかを認識していません。

1 つのラベルを IBOutlet に接続し、3 つのボタン (再生、一時停止、リセット) (各 IBAction に 1 つ) を接続するコードを実行したところ、完全に実行されました。

于 2014-10-02T04:04:15.967 に答える