我正在制作一款卡牌游戏。我希望卡背显示一张图片,卡面显示卡牌内容。我已经成功让图片出现在卡背,但我无法解决当选中时如何清除该图片的问题。(所有选中时运行的代码都在运行,所以我知道这不是实际上没有改变状态的问题。)以下是我的代码:
-(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]];
}
}
有没有关于我做错了什么的想法?