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

╄→尐↘猪︶ㄣ 提交于 2019-12-01 12:13:57

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!