LoginSignup
1
1

More than 3 years have passed since last update.

CustomCellに値を代入したときにFatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: custom cell: file xxxというエラーが出たときの対処法

Last updated at Posted at 2020-03-01

nibで作成したCustom cellに値を入れようとした時に次のエラーが出ました。

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: custom cell: file xxx

結論

  • tableViewのregisterメソッドが間違っていた。
before
tableView.register(UserSearchCell.self, forCellReuseIdentifier: UserSearchCell.className)
after
tableView.register(UINib(nibName: UserSearchCell.className, bundle: nil), forCellReuseIdentifier: UserSearchCell.className)

cellをコードで実装している時はbeforeが正しくて、cellをnibで作成した時はafterでテーブルセルの作成に使用するクラスを登録しないといけないかと思われます。

参考

register(_:forCellReuseIdentifier:) - UITableView | Apple Developer Documentation

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1