2015-09-21 56 views
0

我正在製作一個小型的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!" 
    } 
} 

enter image description here

enter image description here

enter image description here

+2

檢查與此視圖控制器關聯的xib。在xCode中搜索「ButtonIn」。你應該在那裏找到它。 – ajmccall

+0

是的,看起來你在故事板中有一些設置錯誤。你可以張貼你如何連接網點和操作的截圖嗎? –

+1

此外,這是一個質量很低的問題。標題是多餘的。請查看SO指導原則,否則您將無法獲得答案,您的問題將被拒絕投票。 http://stackoverflow.com/help/how-to-ask – ajmccall

回答

1

通常在綁定插座更改時發生這種情況。請按照下面提到的步驟操作:

  • 轉到.xib文件或故事板場景,以獲得此問題。
  • 選擇「文件的所有者」
  • 選擇。如果您發現任何感嘆號ButtonIn連接,然後重新將其綁定「顯示連接檢查」右邊的面板
  • 上。

希望這會有所幫助。

enter image description here

+0

我沒有看到任何.xib文件.. –

+0

在您的Xcode項目導航器中,您可以看到ViewController類的.xib文件。 如果沒有,那麼你可能會使用故事板。如果是這樣,請在故事板中選擇您的視圖控制器並按照上述步驟操作 –

+0

我討厭這麼說,但我找不到「檔案所有者」在哪裏。 –

相關問題