質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

2572閲覧

this class is not key value coding-compliant for the key.

Kaguya_4869

総合スコア116

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2020/03/05 10:54

#質問したいこと
現在、Todoアプリのようなものを作成中です。
そこで、下記のようなエラーが出てきました。

this class is not key value coding-compliant for the key contentLabel.

接続をもう一度つなぎ直したりして確認してみましたが、それでも落ちてしまいます。
#コード

//一番最初の画面 import UIKit final class ViewController: UIViewController { // MARK: IBOutlet @IBOutlet weak var tableView: UITableView! // MARK: Properties private let model = UserDefaultsModel() private var dataSource: [Memo] = [Memo]() { didSet { tableView.reloadData() } } // MARK: Lifecycle static func instance() -> ViewController { let vc = UIStoryboard(name: "ViewController", bundle: nil).instantiateInitialViewController() as! ViewController return vc } override func viewDidLoad() { super.viewDidLoad() configureUI() configureTableView() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) loadMemos() } // MARK: IBAction @objc private func onTapAddButton(_ sender: UIBarButtonItem) { let vc = AddViewController.instance() navigationController?.pushViewController(vc, animated: true) } } // MARK: - Configure extension ViewController { private func configureUI() { navigationItem.title = "メモ一覧" navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(onTapAddButton(_:))) } private func configureTableView() { tableView.delegate = self tableView.dataSource = self tableView.tableFooterView = UIView() tableView.rowHeight = TableViewCell.rowHeight tableView.register(TableViewCell.nib, forCellReuseIdentifier: TableViewCell.reuseIdentifier) } } // MARK: - Model extension ViewController { private func loadMemos() { guard let memos = model.loadMemos() else { return } self.dataSource = memos } } // MARK: - TableView dataSource, delegate extension ViewController: UITableViewDataSource, UITableViewDelegate { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return dataSource.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { tableView.register(TableViewCell.self, forCellReuseIdentifier: NSStringFromClass(TableViewCell.self)) let cell = tableView.dequeueReusableCell(withIdentifier: TableViewCell.reuseIdentifier, for: indexPath) as! TableViewCell let memo = dataSource[indexPath.row] cell.setupCell(title: memo.title, content: memo.content) return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) let memo = dataSource[indexPath.row] let vc = DetailViewController.instance(memo) // セルの選択を解除 tableView.deselectRow(at: indexPath, animated: true) // 別の画面に遷移 performSegue(withIdentifier: "toDetail", sender: nil) navigationController?.pushViewController(vc, animated: true) } }
//TableViewCell import UIKit class TableViewCell: UITableViewCell { // MARK: IBOutlet @IBOutlet private weak var titleLabel: UILabel! @IBOutlet private weak var contentLabel: UILabel! // MARK: Static properties static let reuseIdentifier = "TableViewCell" static let rowHeight: CGFloat = 60 // 正しいファイルを読み込むように引数nibNameに渡す文字列を変更. static var nib: UINib { return UINib(nibName: "TableViewCell", bundle: nil) } // MARK: Overrides override func awakeFromNib() { super.awakeFromNib() } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) } // MARK: Setup func setupCell(title: String, content: String) { titleLabel.text = title contentLabel.text = content } }

#やってみたこと
接続を確認してみました。
#エラー

this class is not key value coding-compliant for the key contentLabel.

よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

接続をやり直すだけでなく、以前の接続を消してみる作業はやっていますでしょうか。

swift初心者:「this class is not key value coding-compliant for the key」の対処方法

投稿2020/03/05 11:25

TsukubaDepot

総合スコア5086

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Kaguya_4869

2020/03/05 11:38

できました! ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問