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

Chapter 5. Building Complex Layouts with Collection Views

5.0. Introduction

Table views are great. They really are. However, they are very rigid in that they always render their content vertically. They aren’t grids and weren’t meant to act like grids. However, as a programmer, you may find yourself in a situation where you want to draw a grid-like component with columns and rows, and put different types of UI objects in each one, or make each one interactive. In a table view, you essentially have one column containing multiple rows. If you want to create an illusion of multiple columns, you will have to provide a custom cell and make that cell look like it is constructed out of multiple columns.

Collection views, just like table views, are based on the concept of cells, with each cell containing an item or view that it renders on the screen. Cells in collection views are reusable, just like in table views, and they can be dequeued and brought back to the screen whenever possible and needed. But the layout can be almost anything you can think of that works in two dimensions.

For this reason, Apple introduced collection views in version 6 of the iOS SDK. A collection view is simply a scroll view on steroids. It has a data source and a delegate, just like a table view, but it has one property that sets it apart from table views or scroll views: the layout object.

What the layout object does is essentially calculate where each item in the collection view has to be placed. Apple has made ...

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