-1

I have an array like this :

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

It is displayed in a TableViewController:

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

        } // ou if cell is MyTableViewCell

        return cell

    }

When I click on an item it opens a ViewController with the name of the item clicked and it should have a button that close this viewController. This is to display the view controller when an item is clicked :

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]

        }

    }

This is the ViewController :

 @IBAction func closeButton(_ sender: Any) {

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

    }

    @IBOutlet weak var myDetail: UILabel!

But when I run the application I get a crash and this error :

TableViewController[11561:421467] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key closeButton.'

When I delete the button it works, I don't understand why, can someone have any ideas ?

jscs
  • 63,694
  • 13
  • 151
  • 195
Sam Caneau
  • 69
  • 1
  • 1
  • 11
  • Possible duplicate of [Xcode 6: this class is not key value coding-compliant](https://stackoverflow.com/questions/26353378/xcode-6-this-class-is-not-key-value-coding-compliant) – jscs Jun 06 '17 at 21:57

1 Answers1

0

I found the problem, here my new ViewController :

@IBAction func closeButton(_ sender: Any) {

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

    }

    @IBOutlet weak var myDetail: UILabel!

    @IBOutlet weak var closeButton: UIButton!
Sam Caneau
  • 69
  • 1
  • 1
  • 11