我正在做一个纸牌游戏。我希望卡片背面显示图像,卡片正面显示卡片内容。我已经将图像显示在背面,但我不知道在选择它时如何清除它。(所有 run-this-code-when-it's-selected 代码都在运行,所以我知道这不是没有实际改变状态的问题。)这是我的代码:
-(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]];
}
}
关于我做错了什么有什么想法吗?