EXC_BREAKPOINT in xcode 6

余生长醉 提交于 2020-01-17 09:28:07

问题


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.



来源:https://stackoverflow.com/questions/26774548/exc-breakpoint-in-xcode-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!