最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】iOS带Storyboard的项目出错:Fatal error init(coder:) has not been implemented

iOS crifan 6419浏览 0评论

折腾:

【已解决】iOS的项目中swift文件中如何获得Storyboard中的UITextField控件

期间,对于带Storyboard的iOS项目中:

swift中的UIViewController来说,已有:

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }

的前提下,根据提示再加上:

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

结果运行后出错:

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

Fatal error init(coder:) has not been implemented

ios – fatal error: init(coder:) has not been implemented error despite being implemented – Stack Overflow

加上:

super.init(coder: aDecoder)

即可。

【总结】

有Storyboard的iOS项目中,UIViewController的初始化,不运行

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }

而是运行:

    required init?(coder aDecoder: NSCoder) {
        //fatalError(“init(coder:) has not been implemented”)
        super.init(coder: aDecoder)
    }

去初始化的。

而其中的:

        super.init(coder: aDecoder)

就是可以从Storyboard去初始化,就可以了。

转载请注明:在路上 » 【已解决】iOS带Storyboard的项目出错:Fatal error init(coder:) has not been implemented

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.165 seconds, using 22.07MB memory