2014-10-02 111 views
0

所以我正在通過一個教程,我已經確保我跟着作者的信,我的代碼會引發以下錯誤。NSUnknownKeyException這個類不是密鑰編碼兼容的密鑰

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,完整iOS8上和斯威夫特場..提前任何幫助

感謝。

回答

2

「這個類不是關鍵值符合編碼的關鍵暫停」通常意味着你有一個引用插座問題。在Connections Inspector中查找不同的按鈕。您可能會要麼有:一個鍵

2個引用網點和程序不知道用哪個NE等

我跑的代碼掛鉤1個標籤,一個IBOutlet和三個按鍵(播放,暫停,重置),每個IBAction一個,並且運行完美。

+0

謝謝,我會檢查現在併發回... – 2014-10-02 04:35:33

+0

問題解決了,謝謝。我會盡量記住一旦我擁有獎賞就投票。 – 2014-10-02 06:08:19

+0

@ user1664443我可以爲你效勞:-)如果答案適用於你,請記得接受它 – 2014-10-02 06:14:16

相關問題