2016-12-08 7 views
0

Swiftでコーディングするのは初めてですが、UIViewControllerの内部にUITableViewを挿入しようとしていますが、画面にナビゲートするとUITableView、次のエラーでアプリがクラッシュすると:NSUnknownKeyException:このクラスはキーのキー値に符合していません

2016-12-08 14:22:47.265712 Evil Quest[300:18048] Unknown class QuestCell in Interface 
Builder file. 
2016-12-08 14:22:47.270248 Evil Quest[300:18048] *** Terminating app due to uncaught 
exception 'NSUnknownKeyException', reason: '[<UITableViewCell 0x101847600> 
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key 
lblQuestName.' 

私は私が間違ってやっているとありますので、もし私が、私はここに投稿すべき私のコードの一部ではわからないものを、非常にわからないんだけどあなたはこの問題を解決するために必要なコードの一部を私に教えてもらい、それを質問に追加します。

ありがとうございます。

EDIT:

cellForRowAt機能:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell:QuestCell = tableView.dequeueReusableCell(withIdentifier: "QuestCell", for: indexPath as IndexPath) as! QuestCell 

    let row = indexPath.row 
    cell.lblQuestName.text = quests[row].name 

    return cell 
} 

QuestCellクラスコード:

import UIKit 

class QuestCell: UITableViewCell { 

    @IBOutlet weak var lblQuestName: UILabel! 

    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
    } 

    override func setSelected(_ selected: Bool, animated: Bool) { 
     super.setSelected(selected, animated: animated) 

     // Configure the view for the selected state 
    } 

} 
+0

あなたcellForRowAtIndexPathメソッドのコードを投稿してください。 –

+0

問題はあなたのセルに関連しています。あなたの質問に関連するコードを追加してください。 QuestCellクラスも同様です。 –

+0

@SagarSnehi、この機能は? –

答えて

2

おそらくクラスを登録する必要があります。 TableViewControllerクラスのviewDidLoadメソッドでこれを試してください。

self.tableView.registerClass(QuestCell.self, forCellReuseIdentifier: "QuestCell") 

また、弱い変数が存在する場合はチェックする必要があります。 あなたのコード行にブレークポイントを置く:

cell.lblQuestName.text = quests[row].name 
+0

セルのようです。lblQuestNameはnilだったので、このエラーが表示されます。致命的なエラー:オプションの値をアンラベリングしている間に予期せずnilが見つかりました –

+0

cell.lblQuestName.textをcell.textLabel?.textに置き換えました。 –

0

GoはあなたがlblQuestNameラベルを設定している場所をストーリーボードにします。ラベルに2つ以上のコンセントが設定されているかどうかを確認します。

1つのコンセントに接続する必要があります。このエラーは、ビューがコンセントに正しく接続されていないとスローされます。

+0

1つのコンセントがあり、QuestCellに接続されています –