I am creating a Tic Tac Toe app. When the game resets, all the Xs and Os UIButton
images should return to nil
. Each space in the board is tagged from 0 to 8.
var buttonsToClear : UIButton
for var i = 0; i < 9; i++ {
buttonsToClear = view.viewWithTag(i) as! UIButton
buttonsToClear.setImage(nil, forState: .Normal)
}
Everything worked fine until I added a Navigation Bar. Now I get the error message
"Could not cast value of type '_UINavigationBarBackground' (0x107e2f2a0) >to 'UIButton' (0x107e357e0). (lldb)
I am absolutely certain that my new Navigation Bar has a tag of "10".
What else could be triggering this message?
You should not use 0 tag, due to 0 is default and you can get any view (in this case the background of the navigation).
Tag the views starting by 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With