Lee Lee - 1 year ago 315
Swift Question

fatal error: init(coder:) has not been implemented error despite being implemented

I am receiving an error message:

fatal error: init(coder:) has not been implemented

For my custom
. The cell is not registered, has the identifier cell in the storyboard and when using dequeasreusablecell. In the custom cell I have the inits as:


override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")

But I still have the error. Thanks.

Answer Source

Replace your init with coder method

required init?(coder aDecoder: NSCoder) {
  super.init(aDecoder: aDecoder)

Actually if you have your cell created in Storyboard - I believe that it should be attached to tableView on which you try to create it. And you can remove both of your init methods if you do not perform any logic there.

UPD: If you need to add any logic - you can do this in awakeFromNib() method.

override func awakeFromNib() {
  //custom logic goes here   
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download