0

I'm creating a simple Tic Tac Toe game in .

My playAgain button causes an uncaught exception, and I can't seem to figure out why.

var buttonToClear : UIButton
for var i = 0; i < 9; i++ {
    buttonToClear = view.viewWithTag(i) as! UIButton
    buttonToClear.setImage(nil, forState: .Normal)
}

Error :

-[TicTacToe.ViewController playAgainButton:]: unrecognized selector sent to instance

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TicTacToe.ViewController playAgainButton:]: unrecognised selector sent to instance

First throw call stack: -[NSObject(NSObject) doesNotRecognizeSelector:]
Sharad Chauhan
  • 4,821
  • 2
  • 25
  • 50

2 Answers2

2

In Interface builder, click on playAgainButton, then click connections inspector button on the right tabbar (it is the right most button). Now look under Sent Events, you will see unwanted connection(s) to outdated functions here, remove them to fix the problem.

If above is not the case, you probably have an unwanted call in your code on button tap.

Kashif
  • 4,642
  • 7
  • 44
  • 97
0

You are not defined the body of playAgainButton method in TicTacToe ViewController.

So please do it

@IBAction func playAgainButton(sender: UIButton) {
    // do your stuff over here
  }
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66