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 ?