見出し画像

[Swift] UITableViewのCellを登録できない(いつもの) -unable to dequeue a cell with identifier Cell-

こんにちワニ。

今日はUITableViewやUICollectionViewを作るとクッソよく遭遇する以下のエラーの解決策をメモとして残します。

試したコード

class CharacterParamTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
   
   @IBOutlet weak var tableView: UITableView!
   
   override func viewDidLoad() {
       super.viewDidLoad()
       tableView.delegate = self
       tableView.dataSource = self
   }
   
   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       let cell = tableView.dequeueReusableCell(withIdentifier: "Celler", for: indexPath)
       return cell
   }
   
   (省略)
}

//追記) StoryboardのCellにIdentifier"Celler"を設定済み
   

発生したエラー

reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

解決策

・viewDidload()に以下のコードを追加

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Celler")

いい加減このミスで詰まるのやめたい

この記事が気に入ったらサポートをしてみませんか?