本文介绍了致命错误:尚未实现init(coder :) Xcode 7 iOS 9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨晚我更新了一个Xcode 6/iOS 8项目,似乎遇到了一些问题.其中之一就是它会抛出致命错误消息并使应用程序崩溃.按下按钮后,我将尝试设置下一个按钮.

I updated an Xcode 6 / iOS 8 project last night and seem to have ran into a few issues. One of them being is it's throwing a fatal error message and crashing the app. When a button is pressed I'm trying to set up the next.

let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("gameViewController")
self.presentViewController(viewController, animated: true, completion: nil)

然后在gameViewController内部,我有这个:

Then inside the gameViewController I have this:

required init(coder aDecoder: NSCoder) {
    // SWIFT 2 update
    state = .OptionsVisible
    super.init(coder: aDecoder)!
    //fatalError("init(coder:) has not been implemented")
}

这似乎是引发致命错误的地方,因为错误消息如下:

This seems to be where the fatal error is being thrown as the error message is the following:

fatal error: init(coder:) has not been implemented: file /pathToApp/GameOptionsViewController.swift, line 81

在我更新到所有内容的最新版本之前,这一切似乎都可以正常工作,而且我不确定什么更改了.

This all seemed to work fine before I updated to the newest versions of everything, and I'm not really sure what changed.

推荐答案

像这样重写:

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.

这篇关于致命错误:尚未实现init(coder :) Xcode 7 iOS 9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 08:00