【问题标题】:Xcode swift Terminating app due to uncaught exception 'NSUnknownKeyException由于未捕获的异常'NSUnknownKeyException,Xcode swift终止应用程序
【发布时间】: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


【解决方案1】:

我发现了问题,这里是我的新 ViewController:

@IBAction func closeButton(_ sender: Any) {

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

    }

    @IBOutlet weak var myDetail: UILabel!

    @IBOutlet weak var closeButton: UIButton!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-17
    • 2012-01-04
    • 2016-08-20
    • 2023-03-11
    • 1970-01-01
    • 2012-06-01
    相关资源
    最近更新 更多