Fun with UICollectionView

Introduced into iOS 6, and like its OS X 10.5 cousin NSCollectionView, I spent some time yesterday with UICollectionView.

I made a PlayingCard View in a PlayingCardGame be a UICollectionViewCell of a UICollectionView.

Here is my tap gesture to the ViewController that flips the playing card:

- (IBAction)flipCard:(UITapGestureRecognizer *)gesture
{
   CGPoint tapLocation = [gesture locationInView:self.cardCollectionView];
   NSIndexPath *indexpath = [self.cardCollectionView indexPathForItemAtPoint:tapLocation];
   if (indexpath) {
      [self.game flipCardAtIndex:indexpath.item];
      self.flipCount++;
      self.gameResult.score = self.game.score;
      [self updateUI];
   }
}

This result is some very clean code.

Tomorrow, Autolayout.

Leave a comment