![見出し画像](https://assets.st-note.com/production/uploads/images/76412469/rectangle_large_type_2_d2d423b228efd027a1855d8e4a061f42.png?width=1200)
[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")
いい加減このミスで詰まるのやめたい