线程1:致命错误:在我的viewDidLoad函数中展开Optional值时意外发现nil

时间:2018-04-11 15:37:08

标签: ios swift

点击“开始游戏”后,我试图让游戏开始弹出。我已经尝试了所有内容并且我一直在获取线程1:致命错误:在第57行打开一个Optional值时意外发现nil(星号为你)  我在viewDidLoad函数中的代码。有谁知道为什么会这样?

class ViewController: UIViewController {


    var caveTunnels = CaveMaze()

    @IBOutlet var helpController: UIView!        
    @IBOutlet weak var descriptionLabel: UILabel!            
    @IBOutlet weak var caveNumber: UITextField!


    func setDescription(){
        descriptionLabel.text! = caveTunnels.description
    }


    @IBAction func helpPopover(_ sender: Any) {
        self.view.addSubview(helpController)
        helpController.center = self.view.center
    }

    @IBAction func helpClose(_ sender: Any) {
        self.helpController.removeFromSuperview()
    }


    @IBAction func moveButton(_ sender: Any) {
        let caveNum = caveNumber.text!
        guard caveNum.count > 0 else { return }
        self.descriptionLabel.text = caveTunnels.move(into: Int(caveNum)!)
    }

    @IBAction func tossButton(_ sender: Any) {
        var caveNum = caveNumber.text!
        guard caveNum.count > 0 else { return caveNum = "1" }
        self.descriptionLabel.text = caveTunnels.toss(into: Int(caveNum)!)
    }

    **override func viewDidLoad() {
        super.viewDidLoad()
        let caveTunnels = CaveMaze()
        **descriptionLabel.text = caveTunnels.description**

    }**

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

0 个答案:

没有答案