Fatal Error: Init(Coder:) Has Not Been Implemented Error Despite Being Implemented

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

Replace your init with coder method:

required init?(coder aDecoder: NSCoder) {
super.init(coder: 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() {
super.awakeFromNib()
//custom logic goes here
}

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

You haven't implemented it, you are just throwing a fatalError, when running from stroy-board this init is getting executed, replace the following code:

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

With this:

required init?(coder: NSCoder) {
form = Form()
super.init(coder: coder)
}

Thread 1: Fatal error: init(coder:) has not been implemented

Finally I found a solution. The problem was a lost segue connection. I reconnect the segue without changing anything in the program and the solution was come.

Thanks, I appreciate your solution recommendations.

Swift Thread 1: Fatal error: init(coder:) has not been implemented (Calling super solution doesn't work)

Whenever ViewController initialising form Storyboard/XIB, it doing it by init(coder: )

Your base class DatasourceController override initialisers

public init() {
super.init(collectionViewLayout: UICollectionViewFlowLayout())
}

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

So when you calling super.init(coder:...) in your HomeController, it will actually call fatalError("init(coder:) has not been implemented") Seems whoever wrote this class, is not a great storyboard/xib lover.

You can delete remove both initialisers in DatasourceController, but make sure that you setting up Flow layout in storyboard. Or you can change them to call super.

If you can't change base class, you can't load your VC from Storyboard.

fatal error: init(coder:) has not been implemented Xcode 7 iOS 9

Rewrite like this:

required init?(coder aDecoder: NSCoder) {
state = .OptionsVisible
super.init(coder: aDecoder)
}

Notice the question mark in the first line and the lack of exclamation mark in the last line.

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

Implement the init(coder:) method:

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

A more in-depth answer can be found in another Stack Overflow answer.

Full example:

var bubbleImageView: UIImageView!
var messageLabel: UILabel!

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

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setup()
}

private func setup() {
bubbleImageView = UIImageView(image: bubbleImage.incoming, highlightedImage: bubbleImage.incomingHighlighed)
bubbleImageView.tag = bubbleTag
bubbleImageView.userInteractionEnabled = true // #CopyMesage

messageLabel = UILabel(frame: CGRectZero)
messageLabel.font = UIFont.systemFontOfSize(15)
messageLabel.numberOfLines = 0
messageLabel.userInteractionEnabled = false // #CopyMessage

selectionStyle = .None

contentView.addSubview(bubbleImageView)
bubbleImageView.addSubview(messageLabel)

bubbleImageView.setTranslatesAutoresizingMaskIntoConstraints(false)
messageLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
contentView.addConstraint(NSLayoutConstraint(item: bubbleImageView, attribute: .Left, relatedBy: .Equal, toItem: contentView, attribute: .Left, multiplier: 1, constant: 10))
contentView.addConstraint(NSLayoutConstraint(item: bubbleImageView, attribute: .Top, relatedBy: .Equal, toItem: contentView, attribute: .Top, multiplier: 1, constant: 4.5))
bubbleImageView.addConstraint(NSLayoutConstraint(item: bubbleImageView, attribute: .Width, relatedBy: .Equal, toItem: messageLabel, attribute: .Width, multiplier: 1, constant: 30))
contentView.addConstraint(NSLayoutConstraint(item: bubbleImageView, attribute: .Bottom, relatedBy: .Equal, toItem: contentView, attribute: .Bottom, multiplier: 1, constant: -4.5))

bubbleImageView.addConstraint(NSLayoutConstraint(item: messageLabel, attribute: .CenterX, relatedBy: .Equal, toItem: bubbleImageView, attribute: .CenterX, multiplier: 1, constant: 3))
bubbleImageView.addConstraint(NSLayoutConstraint(item: messageLabel, attribute: .CenterY, relatedBy: .Equal, toItem: bubbleImageView, attribute: .CenterY, multiplier: 1, constant: -0.5))
messageLabel.preferredMaxLayoutWidth = 218
bubbleImageView.addConstraint(NSLayoutConstraint(item: messageLabel, attribute: .Height, relatedBy: .Equal, toItem: bubbleImageView, attribute: .Height, multiplier: 1, constant: -15))
}


Related Topics



Leave a reply



Submit