I'm working on a card game. I want the card backs to show an image and the card fronts to show the card contents. I've gotten the image to show on the back, but I can't figure out how to clear it when it's selected. (All the run-this-code-when-it's-selected code is running, so I know it's not a question of not actually changing state.) Here's my code:
-(void)updateUI {
for (UIButton *cardButton in self.cardButtons) {
Card *card = [self.game cardAtIndex:[self.cardButtons indexOfObject:cardButton]];
[cardButton setTitle:card.contents forState:UIControlStateSelected];
[cardButton setTitle:card.contents forState:UIControlStateSelected | UIControlStateDisabled];
[cardButton setImage:[UIImage imageNamed:@"cardback.png"] forState:UIControlStateNormal];
//I've tried various permutations of the following three lines, but the image never disappears.
[cardButton setImage:nil forState:UIControlStateSelected];
[cardButton setImage:nil forState:UIControlStateSelected | UIControlStateHighlighted];
[cardButton setImage:nil forState:UIControlStateNormal];
cardButton.selected = card.faceUp;
cardButton.alpha=(card.unplayable ? 0.3:1.0);
[self.scoreLabel setText:[NSString stringWithFormat:@"Score: %d",self.game.score]];
}
}
Any thoughts about what I'm doing wrong?