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

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

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

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

Swift

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

Q&A

0回答

706閲覧

this class is not key value coding-compliant 〜 というメッセージにつきまして

mispoc

総合スコア0

Xcode

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

Swift

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

0グッド

0クリップ

投稿2020/07/18 06:15

前提・実現したいこと

アコーディオンメニュー(目次)画面と、その中の項目を押すことで
説明画面に遷移するという2画面の電子書籍のようなアプリを作成できればと考えてます。
独学の開発初心者です。

発生している問題・エラーメッセージ

実行すると、シミュレーター画面に目次が表示されるところまではいきました。
そのうちの項目を押して遷移できればと思うのですが、以下のエラーメッセージが出てきます。
出てくるのは、AppDelegateの先頭のほうにある Class AppDelegate:〜 の行のところです。

Thread 1: Exception: "[<●プロジェクト名●.NextViewController 0x7fd4f250e070> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ●Label名●."

該当のソースコード(ViewController、AppDelegate、NextViewController)

import UIKit class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var NextViewController: UITableView! var foldingFlg1 = false var foldingFlg2 = false var foldingFlg3 = false // 配列 var items1: NSMutableArray = ["0-1", "0-2", "0-3", "0-4"] var items2: NSMutableArray = ["1-1", "1-2","1-3","1-4"] var items3: NSMutableArray = ["2-1", "2-2","2-3","2-4"] var section1: Dictionary = [String:NSMutableArray]() var section2: Dictionary = [String:NSMutableArray]() var section3: Dictionary = [String:NSMutableArray]() var sections: Array = [Dictionary<String,NSMutableArray>]() // MARK: アクション @objc func tapHeader(gestureRecognizer: UITapGestureRecognizer) { // タップされたセクションを取得する。 guard let section = gestureRecognizer.view?.tag as Int? else { return } // フラグを設定する。 switch section { case 0: foldingFlg1 = foldingFlg1 ? false : true case 1: foldingFlg2 = foldingFlg2 ? false : true case 2: foldingFlg3 = foldingFlg3 ? false : true default: break } // タップされたセクションを再読込する。 NextViewController.reloadSections(NSIndexSet(index: section) as IndexSet, with: .none) } // MARK: メソッド override func viewDidLoad() { super.viewDidLoad() // テーブルビューの背景色を設定する。 let bgColor = UIColor.green.withAlphaComponent(0.1) self.NextViewController.backgroundColor = bgColor self.NextViewController.backgroundView?.backgroundColor = bgColor // セクションのタイトルとデータの配列を設定する。 section1 = ["title 0":items1] section2 = ["title 1":items2] section3 = ["title 2":items3] // セクションを配列に設定する。 sections.append(section1) sections.append(section2) sections.append(section3) // デリゲートを設定する。 NextViewController.delegate = self NextViewController.dataSource = self } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // MARK: テーブルビューのデリゲードメソッド // UIViewを返す。 func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { // セクションのヘッダとなるビューを作成する。 let myView: UIView = UIView() let label:UILabel = UILabel() for (key) in sections[section].keys { label.text = key } label.sizeToFit() label.textColor = UIColor.black myView.addSubview(label) myView.backgroundColor = UIColor(red: 0.3, green: 0.7, blue: 1.1, alpha: 1.0) // セクションのビューに対応する番号を設定する。 myView.tag = section // セクションのビューにタップジェスチャーを設定する。 myView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.tapHeader(gestureRecognizer:)))) return myView }
import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { return true } func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { } }
import UIKit class NextViewController: UIViewController { var data:Dictionary<String,String> = [:] @IBOutlet weak var Label1: UILabel! @IBOutlet weak var Label2: UILabel! @IBOutlet weak var Label3: UILabel! @IBOutlet weak var Label4: UILabel! @IBOutlet weak var Label5: UILabel! @IBOutlet weak var Label6: UILabel! @IBOutlet weak var Label7: UILabel! @IBOutlet weak var Label8: UILabel! @IBOutlet weak var Label9: UILabel! @IBOutlet weak var Label10: UILabel! @IBOutlet weak var Label11: UILabel! @IBOutlet weak var Label12: UILabel! @IBOutlet weak var Label13: UILabel! @IBOutlet weak var Label14: UILabel! override func viewDidLoad() { super.viewDidLoad() self.Label2.text = self.data["firstDetail"] self.Label4.text = self.data["secondDetail"] self.Label6.text = self.data["thirdDetail"] self.Label8.text = self.data["fourthDetail"] self.Label10.text = self.data["fifthDetail"] self.Label12.text = self.data["sixthDetail"] self.Label14.text = self.data["seventhDetail"] } }

試したこと

ネットで調べたところ、outlet接続に関係したものではないかということで、
いったん接続を外し、再接続しましたが変化ありませんでした。
また、エラーメッセージで検索をかけるなど、ネットで調べてまいりましたが、
何をやったらいいのか正直まったくわからない状況です。

基礎的な知識が不足しているのは十分承知しているとはいえ、
この先どのように進めたらいいのか限界を感じこちらに投稿させて頂きました。

ご回答いただけますと大変ありがたいです。よろしくお願いいたします。

補足情報(FW/ツールのバージョンなど)

Xcode11.5 です

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

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

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

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

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

TsukubaDepot

2020/07/18 10:13

ViewController のコードが中途半端なのですが、全て乗せていただくことは可能でしょうか。
MasakiHori

2020/07/19 01:16

NextViewControllerに●Label名●という名前の@objcなプロパティがないというエラーですが、いろいろ伏せられているのでそれ以上は分かりません
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問