致命错误 - 标签文本意外发现

时间:2017-07-11 00:45:38

标签: ios swift fatal-error

我一直有这个错误,我不知道如何解决它。我尝试重新连接我的插座,并重写整个代码。我之前没有遇到过这个问题。错误行已注释。我知道stackoverflow上已经存在很多相同的问题,但我仍然真的不知道如何解决这个问题,对不起。

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var scoreLabel: UILabel!
    @IBOutlet weak var gestureLabel: UILabel!
    @IBOutlet weak var countDownLabel: UILabel!

    var timerCount = 3
    var timerRunning = false
    var countDownEnded = false
    var gameStarted = false
    var k = 0

    override func viewDidLoad() {
        super.viewDidLoad()

        let swipeUp: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(gesture:)))
        swipeUp.direction = .up
        view.addGestureRecognizer(swipeUp)

        let swipeDown: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(gesture:)))
        swipeDown.direction = .down
        view.addGestureRecognizer(swipeDown)

        let swipeLeft: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(gesture:)))
        swipeLeft.direction = .left
        view.addGestureRecognizer(swipeLeft)

        let swipeRight: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(gesture:)))
        swipeRight.direction = .right
        view.addGestureRecognizer(swipeRight)

        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(respondToTapGesture(gesture:)))
        view.addGestureRecognizer(tap)

        let pinch: UIPinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(respondToPinchGesture(gesture:)))
        view.addGestureRecognizer(pinch)


        countDownLabel.text = "" // Error

        if timerCount == 0 {
            timerRunning = false
        }

        settingUp()
        countDown()
    }

    func settingUp() {
        gameStarted = false
        scoreLabel.text = "0" //Error #2
    }
}

我尝试删除该行代码并弹出另一个错误,第二个错误被注释。我甚至尝试删除那行代码,但它只是弹出另一行代码,这是完全相同的错误消息:

  

致命错误:在解包可选值时意外发现nil。

请有人帮助我,这让我这么久。

0 个答案:

没有答案