致命错误:在展开可选值swift错误时意外发现nil

时间:2016-04-06 02:34:23

标签: xcode swift

我正在编写一个简单的程序来显示和删除图像,我不断收到错误

fatal error: unexpectedly found nil while unwrapping an Optional value

这是我的代码:

@IBAction func BeginButton(sender: AnyObject) {
    self.Retry.hidden = false
    self.Begin.hidden = true
    self.Logo.hidden = true
    self.GameOver.hidden = false
    self.ScoreBoard.hidden = false
}

@IBAction func RetryButton(sender: AnyObject) {
    self.Begin.hidden = false
    self.Retry.hidden = true
    self.Logo.hidden = false
    self.GameOver.hidden = true
    self.ScoreBoard.hidden = true
}

请帮助我!

1 个答案:

答案 0 :(得分:3)

您需要将IBOutlets(self.Retry,self.Begin,...)与Interface Builder中的相应视图相关联。现在,其中一个或多个是nil

以下是Apple的详细解释: https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson3.html