2017-06-06 69 views
-1

我有一個這樣的數組:Xcode中迅速終止應用程序由於未捕獲的異常「NSUnknownKeyException

let listCourse = ["Pommes", 
         "Framboises", 
         "Pâtes", 
         "Tomates", 
         "Boudoirs", 
         "Coca", 
         "Lait"] 

它顯示在一個TableViewController:

 if let mycell = cell as? MyTableViewCell { 
      mycell.myLabel.text = self.listCourse[indexPath.row] 

     } // ou if cell is MyTableViewCell 

     return cell 

    } 

當我點擊一個項目它會打開一個ViewController與被點擊的項目的名稱,它應該有一個關閉這個viewController的按鈕。 這是爲了顯示項目被點擊視圖控制器:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     tableView.deselectRow(at: indexPath, animated: true) 
     print("Select article \(self.listCourse[indexPath.row])") 

     let storyboard = UIStoryboard(name:"Main", bundle:nil) 
     if let controller = storyboard.instantiateViewController(withIdentifier: "ViewController") as? ViewController{ 
      self.present(controller, animated: true){ 

      } 
      controller.myDetail.text = self.listCourse[indexPath.row] 

     } 

    } 

這是視圖控制器:

@IBAction func closeButton(_ sender: Any) { 

     self.dismiss(animated: true, completion: nil) 

    } 

    @IBOutlet weak var myDetail: UILabel! 

但是當我運行的應用程序,我得到一個崩潰而這個錯誤:

TableViewController [11561:421467] ***由於未捕獲的異常'NSUnknownKeyException',原因:'[setValue:forUndefinedKey:]:此類不是關鍵字值closeButton的編碼兼容應用程序'。

當我刪除它的作品的按鈕,我不明白爲什麼,有人可以有任何想法?

+0

的可能的複製[Xcode中6:此類不是密鑰值符合編碼-(https://stackoverflow.com/questions/26353378/ xcode中-6-此級此結果未鍵值編碼兼容的) –

回答

0

我發現這個問題,我在這裏的新的視圖控制器:

@IBAction func closeButton(_ sender: Any) { 

     self.dismiss(animated: true, completion: nil) 

    } 

    @IBOutlet weak var myDetail: UILabel! 

    @IBOutlet weak var closeButton: UIButton! 
相關問題