【发布时间】:2017-11-08 01:40:14
【问题描述】:
我有一个这样的数组:
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 的键值编码不兼容。”
当我删除它工作的按钮时,我不明白为什么,有人可以有什么想法吗?
【问题讨论】:
标签: ios swift uiviewcontroller nib