Sunday, 15 September 2013

Objective-C setTitle forState method

Objective-C setTitle forState method

I'm developing an application which has a view of only one card and
everytime this card is clicked the card shows a random card from the deck.
I already implemented a deck class which has drawRandomCard method which
draws a random card
@interface Deck()
@property (strong,nonatomic) NSMutableArray *cards; //of Card
@end
@implementation Deck
- (NSMutableArray *)cards
{
if(!_cards){
_cards= [[NSMutableArray alloc]init];
}
return _cards;
}
- (void)addCard:(Card *)card atTop:(BOOL)atTop{
if(atTop)
{
[self.cards insertObject:card atIndex:0];
}
else
{
[self.cards addObject:card];
}
}
- (Card *)drawRandomCard
{
Card *randomCard = nil;
if(self.cards.count)
{
unsigned index = arc4random() % self.cards.count;
randomCard = self.cards[index];
[self.cards removeObjectAtIndex:index];
}
return randomCard;
}
@end
how can i use the drawRandomCard method in my ViewController and the
setTitle forState method to be able to change the title of the card
according to the card drawn randomly from the drawRandomCard method ?

No comments:

Post a Comment