EXC_BREAKPOINT in xcode 6

2019-08-30 23:19发布

问题:

I have an issue that I can not seem to find the solution for. I am new to Swift and was trying to create a TicTacToe game.

Whenever I finish playing the game in multiplayer mode a play button pops up. I click it and it automatically crashes and indicates there is a breakpoint (EXC_BREAKPOINT)

Reset game button is attached to the @IBAction func

@IBAction func playAgainPressed(sender : AnyObject) {

    goNumber = 1

    winner = 0

    gameState = [0, 0, 0, 0, 0, 0, 0, 0 ,0]

    label.center = CGPointMake(label.center.x - 400, label.center.y)

    playAgain.alpha = 0

    var button : UIButton

    for var i = 0; i < 9; i++ {

        button = view.viewWithTag(i) as UIButton

        button.setImage(nil, forState: .Normal)
    }
}

Whenever I set i = 0 it crashes. Whenever I set i to 1, it works perfectly. While tag 0 is the left upper corner of the game, whenever i = 1 it will reset every button except the upper left button. When I set i = 0 it is suppose to hide the upper left corner as well, but at that point it crashes.

Any thoughts?


How could I set it up so I have my UIButton array and it resets after I press play again? I also do not have multiple views with tag 0. When I renumber my upper left button to 100 instead of 0 I receive a different error that looks like this:

@IBAction func buttonPressed(sender: AnyObject) {

    if (gameState[sender.tag]==0 && winner == 0) {

    var image = UIImage()

    if (goNumber%2==0){
        image = UIImage(named:"o")!
        gameState[sender.tag] = 2
    }else{
        image = UIImage(named:"x")!
        gameState[sender.tag] = 1
    }

" if (gameState[sender.tag]==0 && winner == 0) "

this receives a EXC_BAD_INSTRUCTION errs

I do not know what is wrong with using tag 0 for the upper left corner, as far as I can tell I only have one view with number 0.

回答1:

You should not to use tag 0 as a identifier, it's the default value.

The document says:

The default value is 0. You can set the value of this tag and use that value to identify the view later.

So, you have multiple views with tag 0.