Originally, my code was working.
IBAction func clickedon(_ sender: UIButton) {
if(gamestate[sender.tag] == 0 && gameisactive == true){
gamestate[sender.tag] = activeplayer
if (activeplayer == 1){
print("working")
sender.setImage(UIImage(named:"Cross.png"), for: UIControlState()) <-----------
activeplayer = 2
}
else {
print("working2")
sender.setImage(UIImage(named:"Nought.png"), for: UIControlState()) <-----------
activeplayer = 1
}
}
These two pieces of code that set image were working. These buttons have nothing set to their image. When they are clicked on, I want them to switch to those images. Those images are in the folder with the view controller. I am not sure why they stopped working. I commented out all other code to see if it could be an issue but it doesn't seem to be. The print statements get printed out in both cases. It's just the set image that doesn't seem to do anything. There is no error, it just does nothing.
I don't really understand the UIControlState() code. I am mimicking an online project that has the same code and it works. It is really strange. Please let me know if you have any suggestions!