A Better Layout with UICollectionView

When Apple released iOS 6, they added a new component to UIKit: UICollectionView. UICollectionView is very similar to UITableView in terms of the APIs that are available and the way it handles delegation to other objects. The main difference between the two is that UICollectionView is a lot more powerful and flexible. It provides an easy to use grid layout out of the box. However, you're free to create any type of layout that you desire with a UICollectionView. You could even create a list that looks like a UITableView but has all of the flexibility that UICollectionView provides.

In this chapter, you'll build upon the HelloContacts app that you built in the previous chapter, Chapter 1, UITableView Touch Up. First, all UITableView code should be replaced with UICollectionView code. This will enable you to create a more interesting grid layout to display contacts in.

You'll also create a good-looking custom cell that shows a contact's image and name. To make your layout really stand out, we need to explore the UICollectionViewFlowLayout, which will enable us to implement a pretty cool custom layout. Once the app's looks are improved with custom cells and a custom layout, we'll have a look at performance in comparison to UITableView. Lastly, we'll implement some of the available delegate methods, just as we did with UITableView.

The topics covered in this chapter are as follows: