Swift和XCode的Bug问题

时间:2016-10-03 00:11:46

标签: swift ios10

帮助,我正在编写这个游戏,我不断收到错误消息:

  

主题1:EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)

示例:

(Error Image)

一切正常,直到我为特朗普硬币图片添加了代码,标签上写着'分数:'

import UIKit

class ViewController: UIViewController {

//DEFINING VARIABLES
var gameIsRunning = false
var paused = false

var totalCoins = 0
var totalScore = 0
var gameCoins = 0
var gameScore = 0

@IBOutlet var titleCoinsLabel: UILabel!
@IBOutlet var titleScoreLabel: UILabel!
@IBOutlet var titleTrumpCoin: UIImageView!
@IBOutlet var titleScoreRun: UILabel!
@IBOutlet var gameTitle: UILabel!
@IBOutlet var playButton: UIButton!
@IBOutlet var pauseButton: UIButton!
@IBOutlet var pauseView: UIView!
@IBOutlet var resumeButton: UIButton!
@IBOutlet var optionsButton: UIButton!
@IBOutlet var tutorialButton: UIButton!
@IBOutlet var rateApp: UIButton!
@IBOutlet var quitButton: UIButton!
@IBOutlet var tutorialBackButton: UIButton!
@IBOutlet var tutorialView: UIView!
@IBOutlet var titleOptions: UIButton!
@IBOutlet var titleTutorial: UIButton!
@IBOutlet var optionsView: UIView!
@IBOutlet var optionsBack: UIButton!





//WHEN GAME LOADS WHAT TO DO
override func viewDidLoad() {
    super.viewDidLoad()

    gameIsRunning = false

    pauseButton.isHidden = true
    pauseButton.isEnabled = false
    pauseButton.layer.cornerRadius = 10
    pauseButton.alpha = 0.75

    pauseView.isHidden = true
    pauseView.layer.cornerRadius = 20

    tutorialView.isHidden = true

    resumeButton.layer.cornerRadius = 8
    optionsButton.layer.cornerRadius = 8
    tutorialButton.layer.cornerRadius = 8
    rateApp.layer.cornerRadius = 8
    quitButton.layer.cornerRadius = 8
    tutorialBackButton.layer.cornerRadius = 8
    optionsView.layer.cornerRadius = 20
    optionsBack.layer.cornerRadius = 8
    optionsView.isHidden = true

    titleCoinsLabel.text = String(totalCoins)

}





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





//STARTING GAME
@IBAction func startGame(_ sender: AnyObject) {

    if gameIsRunning == false {

        gameIsRunning = true

        titleCoinsLabel.isHidden = true
        titleScoreLabel.isHidden = true

        playButton.isHidden = true
        playButton.isEnabled = false

        gameTitle.isHidden = true
        gameTitle.isEnabled = false

        pauseButton.isHidden = false
        pauseButton.isEnabled = true

        titleTutorial.isHidden = true
        titleTutorial.isEnabled = false

        titleOptions.isHidden = true
        titleOptions.isEnabled = false

        titleScoreRun.isHidden = true
        titleTrumpCoin.isHidden = true

        //NOT DEFINED YET
        runGame()

    }

}


//PAUSE
@IBAction func pauseGame(_ sender: AnyObject) {

    paused = true

    pauseView.isHidden = false

}

//RESUME
@IBAction func resumeGame(_ sender: AnyObject) {

    paused = false

    pauseView.isHidden = true

}

//VIEW OPTIONS
@IBAction func optionsView(_ sender: AnyObject) {

    optionsView.isHidden = false

    pauseView.isHidden = true

}

@IBAction func titleOptionsView(_ sender: AnyObject) {

    optionsView.isHidden = false

}

//BACK FROM OPTIONS
@IBAction func optionsBack(_ sender: AnyObject) {

    optionsView.isHidden = true

    if (paused == true) {

        pauseView.isHidden = false

    } else {

        pauseView.isHidden = true

    }

}

//OPTIONS TWEAKS
@IBAction func gameVolumeSlider(_ sender: AnyObject) {



}

@IBAction func musicVolumeSlider(_ sender: AnyObject) {



}

//VIEW TUTORIAL
@IBAction func tutorialView(_ sender: AnyObject) {

    pauseView.isHidden = true
    tutorialView.isHidden = false

}

@IBAction func titleTutorial(_ sender: AnyObject) {

    tutorialView.isHidden = false

}

//BACK FROM TUTORIAL
@IBAction func backTutorial(_ sender: AnyObject) {

    tutorialView.isHidden = true

    if (paused == true) {

        pauseView.isHidden = false

    } else {

        pauseView.isHidden = true

    }

}


//RATE APP
@IBAction func rateApp(_ sender: AnyObject) {



}

//QUIT GAME
@IBAction func quitGame(_ sender: AnyObject) {

    titleScoreLabel.isHidden = false
    titleCoinsLabel.isHidden = false

    pauseButton.isHidden = true
    pauseView.isHidden = true

    gameTitle.isHidden = false
    gameTitle.isEnabled = true
    playButton.isHidden = false
    playButton.isEnabled = true

    titleTutorial.isHidden = false
    titleTutorial.isEnabled = true

    titleOptions.isHidden = false
    titleOptions.isEnabled = true
    titleScoreRun.isHidden = true

    titleScoreRun.isHidden = false
    titleTrumpCoin.isHidden = false

    titleScoreLabel.text = String(gameScore)
    titleCoinsLabel.text = String(totalCoins)

    totalScore = totalScore + gameScore
    gameScore = 0
    totalCoins = totalCoins + gameCoins
    gameCoins = 0

}




//RECOGNIZING SWIPES
@IBAction func swipeRight(_ sender: AnyObject) {

    if (gameIsRunning == true) {



    }

}

@IBAction func swipeLeft(_ sender: AnyObject) {

    if (gameIsRunning == true) {



    }


}

@IBAction func press(_ sender: AnyObject) {



}




//FUNCTIONS TO RUN GAME
func runGame() {



}

}

1 个答案:

答案 0 :(得分:1)

您似乎没有正确连接titleScoreLabel插座。在Interface Builder中仔细检查一下。