O'Reilly logo

iOS 7 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.1. Constructing Collection Views

Problem

You want to display a collection view on the screen.

Solution

Either use an instance of the UICollectionView as a subview of another view in your app or (if you want a full-screen collection view) use the UICollectionViewController class.

Discussion

Just like table views, a collection view, as its name indicates, is a view and can be added as a subview to other views. So when you are creating your app, think about whether your collection view has to be the main view of a view controller or should appear as a small portion of another view.

Let’s explore the full-screen scenario first. Follow these steps to create a simple app that displays a full-screen collection view on the screen:

  1. Open Xcode.

  2. From the File menu, choose New, and then choose Project.

  3. On the left, choose the iOS main category, and under that choose Application. On the righthand side of the screen, choose Empty Application, and then press the Next button.

  4. On the next screen, enter your project information and ensure that the Use Automatic Reference Counting box is ticked, as shown in Figure 5-3. Once you are done entering the relevant values, press the Next button.

  1. You are now asked to save your project on disk. Choose a suitable place to save your project, and then press the Create button.

  2. Now that you have your project set up, create a new class in your project and call it ViewController. This class has to subclass UICollectionViewController. You won’t need a .xib file for this view ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required