If i am not mistaken you are working on CS193P. With every click you are going through the for loop which is redrawing cards for every button in the collection. You probably have only 52 cards in the deck and after two clicks there are not more cards so [self.deck drawRandomCard]
is returning nil which sets title to nil. You do not have to set all the cards in the setter of the collection you can just set each card in the flipCard when it is flipped. This is my version of the flipCard. It also checks if there are no more cards. Let me know if this what you were looking for.
- (IBAction)flipCard:(UIButton *)sender {
sender.selected = !sender.selected;
if (sender.selected) {
PlayingCard *randomCard = [self.deck drawRandomCard];
if (!randomCard) {
//will alert user no more cards, disable the button and set alpha to 0.3
sender.enabled = NO;
sender.alpha = 0.3;
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No More Cards" message:@"Game Over" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}else{
[sender setTitle:randomCard.contents forState:UIControlStateSelected];
}
}
self.flipCount++;
}